வேர்ட்பிரஸ் வகை/குறிச்சொல்/ஆசிரியர் பக்கத்தை ஒட்டும் கட்டுரைகளைக் காட்டுவது எப்படி?

வேர்ட்பிரஸ்உள்ளமைக்கப்பட்ட கட்டுரை ஒட்டுதல் செயல்பாடு உள்ளது, ஆனால் இயல்பாகவே மேல் பக்கம் மட்டுமே ஒட்டும் கட்டுரைகளைக் காண்பிக்க ஆதரிக்கப்படும்.

பிற காப்பகப் பக்கங்கள் (வகைப் பக்கங்கள், குறிச்சொல் பக்கங்கள், ஆசிரியர் பக்கங்கள் மற்றும் தேதிப் பக்கங்கள் போன்றவை) பின் செய்யப்பட்ட கட்டுரைகளை மேலே காட்ட முடியாது, இயல்புநிலை வரிசையில் மட்டுமே.

WordPress உடன் நிறைய செய்ய வேண்டும்எஸ்சிஓநண்பர்களே, இந்த பிரச்சனைகளை தீர்க்க நம்புகிறேன்.

வேர்ட்பிரஸ் வகை/குறிச்சொல்/ஆசிரியர் பக்கத்தை ஒட்டும் கட்டுரைகளைக் காட்டுவது எப்படி?

உண்மையில், wp-includes/query.php இன் முகப்புப் பக்கத்தின் குறியீட்டை மட்டுமே நாம் பார்க்க வேண்டும் மற்றும் அதைச் சிறிது மாற்றியமைக்க வேண்டும், அதனால் காப்பகப் பக்கத்தின் மேல் (வகைப் பக்கம், தாவல் பக்கம், ஆசிரியர் பக்கம் மற்றும் தேதிப் பக்கம் போன்றவை. ) மேல் கட்டுரையையும் காட்டலாம்.

வேர்ட்பிரஸ் ஒட்டும் கட்டுரை குறியீடு

உங்களின் தற்போதைய தீம் ▼ கீழ் உள்ள functions.php கோப்பில் பின்வரும் குறியீட்டை வைக்கவும்

//让WordPress分类、标签、存档和作者页显示置顶文章
add_filter('the_posts', 'putStickyOnTop' );
function putStickyOnTop( $posts ) {
if ( is_series() || is_home() || !is_main_query() || !is_archive())
return $posts;

global $wp_query;

$sticky_posts = get_option('sticky_posts');

if ( $wp_query->query_vars['paged'] <= 1 && is_array($sticky_posts) && !empty($sticky_posts) && !get_query_var('ignore_sticky_posts') ) { $stickies1 = get_posts( array( 'post__in' => $sticky_posts ) );
foreach ( $stickies1 as $sticky_post1 ) {
// 判断当前是否分类页 
if($wp_query->is_category == 1 && !has_category($wp_query->query_vars['cat'], $sticky_post1->ID)) {
// 移除不是本分类的文章
$offset1 = array_search($sticky_post1->ID, $sticky_posts);
unset( $sticky_posts[$offset1] );
}
if($wp_query->is_tag == 1 && has_tag($wp_query->query_vars['tag'], $sticky_post1->ID)) {
// 移除不是本标签的文章
$offset1 = array_search($sticky_post1->ID, $sticky_posts);
unset( $sticky_posts[$offset1] );
}
if($wp_query->is_year == 1 && date_i18n('Y', strtotime($sticky_post1->post_date))!=$wp_query->query['m']) {
// 移除不是本年份的文章
$offset1 = array_search($sticky_post1->ID, $sticky_posts);
unset( $sticky_posts[$offset1] );
}
if($wp_query->is_month == 1 && date_i18n('Ym', strtotime($sticky_post1->post_date))!=$wp_query->query['m']) {
// 移除不是本月份的文章
$offset1 = array_search($sticky_post1->ID, $sticky_posts);
unset( $sticky_posts[$offset1] );
}
if($wp_query->is_day == 1 && date_i18n('Ymd', strtotime($sticky_post1->post_date))!=$wp_query->query['m']) {
// 移除不是本日期的文章
$offset1 = array_search($sticky_post1->ID, $sticky_posts);
unset( $sticky_posts[$offset1] );
}
if($wp_query->is_author == 1 && $sticky_post1->post_author != $wp_query->query_vars['author']) {
// 移除不是本作者的文章
$offset1 = array_search($sticky_post1->ID, $sticky_posts);
unset( $sticky_posts[$offset1] );
}
}

$num_posts = count($posts);
$sticky_offset = 0;
// Loop over posts and relocate stickies to the front.
for ( $i = 0; $i < $num_posts; $i++ ) {
if ( in_array($posts[$i]->ID, $sticky_posts) ) {
$sticky_post = $posts[$i];
// Remove sticky from current position
array_splice($posts, $i, 1);
// Move to front, after other stickies
array_splice($posts, $sticky_offset, 0, array($sticky_post));
// Increment the sticky offset. The next sticky will be placed at this offset.
$sticky_offset++;
// Remove post from sticky posts array
$offset = array_search($sticky_post->ID, $sticky_posts);
unset( $sticky_posts[$offset] );
}
}

// If any posts have been excluded specifically, Ignore those that are sticky.
if ( !empty($sticky_posts) && !empty($wp_query->query_vars['post__not_in'] ) )
$sticky_posts = array_diff($sticky_posts, $wp_query->query_vars['post__not_in']);

// Fetch sticky posts that weren't in the query results
if ( !empty($sticky_posts) ) {
$stickies = get_posts( array(
'post__in' => $sticky_posts,
'post_type' => $wp_query->query_vars['post_type'],
'post_status' => 'publish',
'nopaging' => true
) );

foreach ( $stickies as $sticky_post ) {
array_splice( $posts, $sticky_offset, 0, array( $sticky_post ) );
$sticky_offset++;
}
}
}

return $posts;
}

//置顶文章添加样式
add_filter('post_class',  'addStickyClass' ,10,3 );
function addStickyClass( $classes, $class, $post_id ){
  if( is_sticky() && is_category() && !isset( $classes['sticky'] ) ){
    $classes[] = 'sticky';
  }
  
  return $classes;
} 

ஒட்டும் கட்டுரையின் குறியீட்டைப் பயன்படுத்துவதற்கான வழிமுறைகள்

1) காப்பகப் பக்கம் எல்லா முக்கிய கட்டுரைகளையும் காட்ட வேண்டுமெனில், 11-43 கோடுகளின் குறியீட்டை நீக்கவும்;

2) மேல் கட்டுரையை வகைப் பக்கத்தில் காட்ட விரும்பவில்லை எனில், 3வது வரியில் ▼ஐச் சேர்க்கவும்

if(

▼ என மாற்றவும்

// abc是分类的名称
if ( is_category( 'abc' ) || 

3) மேல் கட்டுரையை தாவல் பக்கத்தில் காட்ட விரும்பவில்லை எனில், வரி 3 இல் ▼

if(

மாற்ற:

// abc是标签的名称
if ( is_tag( 'abc' ) || 

4) ஆசிரியர் பக்கம் மேல் கட்டுரையைக் காட்டுவதை நீங்கள் விரும்பவில்லை எனில், 3வது வரியில் ▼ செய்யவும்

if(

▼ என மாற்றவும்

// abc是作者的昵称
if ( is_author( 'abc' ) || 

5) மேல் கட்டுரையை தனிப்பயன் வகைப் பக்கம் காட்ட விரும்பவில்லை என்றால், அதை வைக்கவும்

if(

இதை மாற்றவும்:

// series是自定义分类、abc是自定义分类名称
if ( is_series( 'abc' ) ||

காப்பகப் பக்கத்தில் உள்ள இடுகைகளின் பட்டியலைப் பெற நீங்கள் WP_Query அல்லது query_posts ஐப் பயன்படுத்தினால், மேலே உள்ள குறியீடு முதன்மை வளையத்திற்கு மட்டுமே செல்லுபடியாகும்.

நீங்கள் வரி 3 இல் பின்வரும் குறியீட்டை நீக்கலாம் (கட்டுரைகளின் எண்ணிக்கை நீங்கள் அமைத்ததை விட வித்தியாசமாக இருக்கலாம்) ▼

|| !is_main_query() 

மேல் கட்டுரையில் நடையைச் சேர்க்கவும்

நீங்கள் ஒட்டும் இடுகையில் ஸ்டைல்களைச் சேர்க்க விரும்பினால், functions.php இல் பின்வரும் குறியீட்டைச் சேர்த்து, ஒட்டும் இடுகையில் ஒட்டும் என்ற வகுப்பைச் சேர்க்கவும்.

பொதுவான வேர்ட்பிரஸ் தீம்களில், சிறந்த கட்டுரை பாணிக்கு CSS குறியீடு இருக்கும், நீங்கள் தனிப்பயன் சேர்க்கலாம் ▼

//置顶文章添加样式
add_filter('post_class',  'addStickyClass' ,10,3 );
function addStickyClass( $classes, $class, $post_id ){
  if( is_sticky() && is_category() && !isset( $classes['sticky'] ) ){
    $classes[] = 'sticky';
  }
  
  return $classes;
} 

வேர்ட்பிரஸ் வகை காப்பகப் பக்கங்கள் வேர்ட்பிரஸ் கட்டுரைகளை மேலே காட்டுவதற்கு மற்றொரு வழி உள்ளது▼

ஹோப் சென் வெலியாங் வலைப்பதிவு ( https://www.chenweiliang.com/ ) பகிரப்பட்டது "WordPress வகை/குறிச்சொல்/ஆசிரியர் பக்கத்தை ஒட்டும் கட்டுரைகளைக் காட்டுவது எப்படி? , உங்களுக்கு உதவ.

இந்தக் கட்டுரையின் இணைப்பைப் பகிர வரவேற்கிறோம்:https://www.chenweiliang.com/cwl-878.html

சமீபத்திய புதுப்பிப்புகளைப் பெற, சென் வெலியாங்கின் வலைப்பதிவின் டெலிகிராம் சேனலுக்கு வரவேற்கிறோம்!

🔔 சேனல் டாப் டைரக்டரியில் மதிப்புமிக்க "ChatGPT Content Marketing AI கருவி பயன்பாட்டு வழிகாட்டியை" பெறுவதில் முதல் நபராக இருங்கள்! 🌟
📚 இந்த வழிகாட்டியில் பெரும் மதிப்பு உள்ளது, 🌟இது ஒரு அரிய வாய்ப்பு, தவறவிடாதீர்கள்! ⏰⌛💨
பிடித்திருந்தால் ஷேர் செய்து லைக் செய்யுங்கள்!
உங்களின் பகிர்வும் விருப்பங்களும் எங்களின் தொடர்ச்சியான ஊக்கம்!

 

发表 评论

உங்கள் மின்னஞ்சல் முகவரி வெளியிடப்படாது. தேவையான புலங்கள் பயன்படுத்தப்படுகின்றன * லேபிள்

மேலே உருட்டவும்