WordPress အမျိုးအစား/တဂ်/စာရေးဆရာ စာမျက်နှာသည် ကပ်စေးနဲသော ဆောင်းပါးများကို မည်သို့ပြသရမည်နည်း။

WordPressBuilt-in article sticking function ပါရှိသော်လည်း ပုံမှန်အားဖြင့် ထိပ်စာမျက်နှာကိုသာ ကပ်စေးကပ်ထားသော ဆောင်းပါးများကို ပြသရန် ပံ့ပိုးထားသည်။

အခြားသော မှတ်တမ်းစာမျက်နှာများ (ဥပမာ အမျိုးအစား စာမျက်နှာများ၊ တဂ်စာမျက်နှာများ၊ စာရေးဆရာ စာမျက်နှာများနှင့် ရက်စွဲစာမျက်နှာများ) သည် ပုံသေအစီအစဥ်အရသာ အပေါ်ဆုံးတွင် ကပ်စေးနဲသော ဆောင်းပါးများကို မပြသနိုင်ပါ။

WordPress နဲ့ အများကြီး သက်ဆိုင်ပါတယ်။SEO ဆိုသည်မှာသူငယ်ချင်းတို့ ဒီပြဿနာတွေကို ဖြေရှင်းနိုင်မယ်လို့ မျှော်လင့်ပါတယ်။

WordPress အမျိုးအစား/တဂ်/စာရေးဆရာ စာမျက်နှာသည် ကပ်စေးနဲသော ဆောင်းပါးများကို မည်သို့ပြသရမည်နည်း။

အမှန်တော့၊ ကျွန်ုပ်တို့သည် wp-includes/query.php ၏ ပင်မစာမျက်နှာ၏ ကုဒ်ကို ကိုးကားရန်သာ လိုအပ်ပြီး ၎င်းကို အနည်းငယ် မွမ်းမံပြင်ဆင်ရန် လိုအပ်သောကြောင့် မော်ကွန်းစာမျက်နှာ၏ ထိပ်ပိုင်း (အမျိုးအစား စာမျက်နှာ၊ တက်ဘ်စာမျက်နှာ၊ စာရေးဆရာ စာမျက်နှာနှင့် ရက်စွဲစာမျက်နှာ ကဲ့သို့သော၊ ) ထိပ်တန်းဆောင်းပါးကိုလည်း ပြသနိုင်သည်။

WordPress Sticky Article Code

သင့်လက်ရှိဆောင်ပုဒ် ▼ အောက် 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) မော်ကွန်းစာမျက်နှာတွင် ထိပ်တန်းဆောင်းပါးများအားလုံးကို ပြသလိုပါက၊ ကျေးဇူးပြု၍ ကုဒ် ၁၁-၄၃ လိုင်းကို ဖျက်ပါ။

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 တွင် အောက်ပါကုဒ်ကို ပေါင်းထည့်ကာ sticky post တွင် sticky ဟု အမည်ပေးထားသော အတန်းကို ထည့်ပါ။

ယေဘူယျအားဖြင့် WordPress အပြင်အဆင်များတွင် ထိပ်တန်းဆောင်းပါးစတိုင်အတွက် 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;
} 
  • အမျိုးအစားစာမျက်နှာ၏ ထိပ်တန်းဆောင်းပါးစတိုင်အကျိုးသက်ရောက်မှု၊Chen Weiliangဘလော့ဆောင်းပါးအမျိုးအစားများ-တရုတ်မိုဘိုင်းနံပါတ်
  • (အခင်းအကျင်းပြောင်းခြင်း သက်တမ်းကုန်သွားပါပြီ)

WordPress အမျိုးအစား archive စာမျက်နှာများကို ထိပ်ပိုင်းတွင် WordPress ဆောင်းပါးများကို ပြသရန် အခြားနည်းလမ်းတစ်ခုရှိပါသည်။

မျှော်လင့်ခြင်း Chen Weiliang ဘလော့ဂ် ( https://www.chenweiliang.com/ ) မျှဝေထားသည် " WordPress အမျိုးအစား/tag/author စာမျက်နှာသည် ကပ်စေးနဲသော ဆောင်းပါးများကို မည်သို့ပြသမည်နည်း။ , သင့်ကိုကူညီရန်။

ဤဆောင်းပါး၏ link ကိုမျှဝေရန်ကြိုဆိုပါတယ်:https://www.chenweiliang.com/cwl-878.html

နောက်ဆုံးထွက်မွမ်းမံမှုများကို ရယူရန် Chen Weiliang ၏ တယ်လီဂရမ်ချန်နယ်မှ ကြိုဆိုပါသည်။

🔔 ချန်နယ်ထိပ်တန်းလမ်းညွှန်တွင် တန်ဖိုးရှိသော "ChatGPT အကြောင်းအရာစျေးကွက်ရှာဖွေရေး AI ကိရိယာအသုံးပြုမှုလမ်းညွှန်" ကို ပထမဆုံးရရှိသူဖြစ်လိုက်ပါ။ 🌟
📚 ဤလမ်းညွှန်တွင် တန်ဖိုးကြီးကြီးမားမားပါရှိသည်၊ 🌟ဒါက ရှားပါးအခွင့်အရေးပါ၊ လက်လွတ်မခံပါနဲ့။ ⏰⌛💨
ကြိုက်ရင် Share ပြီး Like လုပ်ပါ။
သင်၏မျှဝေခြင်းနှင့် လိုက်ခ်များသည် ကျွန်ုပ်တို့၏ စဉ်ဆက်မပြတ်လှုံ့ဆော်မှုဖြစ်သည်။

 

မှတ်ချက်များ

သင့်ရဲ့အီးမေးလ်လိပ်စာကိုထုတ်ဝေမည်မဟုတ် 用项已用用 * တံဆိပ်

အပေါ်မှလှိမ့်