久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

這篇文章主要為大家介紹了WordPress分類與標(biāo)簽等存檔頁實(shí)現(xiàn)置頂?shù)姆椒?通過二次開發(fā)實(shí)現(xiàn)存檔頁的置頂功能,是非常實(shí)用的技巧,需要的朋友可以參考下

本文實(shí)例講述了WordPress分類與標(biāo)簽等存檔頁實(shí)現(xiàn)置頂?shù)姆椒ā7窒斫o大家供大家參考。具體分析如下:

在wordpress中默認(rèn)能置頂文章就是只有首頁了,如果我們希望分類/標(biāo)簽等存檔頁也能置頂文章我們需要二次開發(fā).

現(xiàn)在參考wp-includes/query.php中首頁置頂?shù)拇a,稍微修改一下,可以讓分類頁、標(biāo)簽頁、作者頁和日期頁等存檔頁面也能像首頁一樣在頂部顯示其范圍內(nèi)的置頂文章,把下面的代碼放到當(dāng)前主題下的functions.php中就可以了.

復(fù)制代碼
代碼如下:
add_filter('the_posts', 'putStickyOnTop' );
function putStickyOnTop( $posts ) {
if(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) && !emptyempty($sticky_posts) && !get_query_var('ignore_sticky_posts') ) { $stickies1 = get_posts( array( 'post__in' => $sticky_posts ) );
foreach ( $stickies1 as $sticky_post1 ) {
// 判斷當(dāng)前是否分類頁
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)) {
// 去除不屬于本標(biāo)簽的文章
$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 ( !emptyempty($sticky_posts) && !emptyempty($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 ( !emptyempty($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;
}

代碼說明:

1、如果你想讓存檔頁也都顯示全部置頂文章,那么就刪掉11-43行的代碼;

【網(wǎng)站聲明】本站除付費(fèi)源碼經(jīng)過測(cè)試外,其他素材未做測(cè)試,不保證完整性,網(wǎng)站上部分源碼僅限學(xué)習(xí)交流,請(qǐng)勿用于商業(yè)用途。如損害你的權(quán)益請(qǐng)聯(lián)系客服QQ:2655101040 給予處理,謝謝支持。

相關(guān)文檔推薦

這篇文章主要介紹了PHP實(shí)現(xiàn)無限極分類生成分類樹的方法,結(jié)合實(shí)例形式簡(jiǎn)單分析了無限極分類的原理與實(shí)現(xiàn)方法,涉及PHP數(shù)組遍歷與判斷相關(guān)操作技巧,需要的朋友可以參考下
wordpress是很多新手站長(zhǎng)搭建個(gè)人博客最喜愛的程序,但是最近在使用WordPress的時(shí)候遇到了一些問題,所以想著將遇到問題總結(jié)分享出來,下面這篇文章主要給大家介紹了關(guān)于wordpress在安
最近在工作中遇到一個(gè)需求,是要在laravel 5.4中實(shí)現(xiàn)無限級(jí)分類,但發(fā)現(xiàn)網(wǎng)上這個(gè)的資料較少,所以只能自己來實(shí)現(xiàn)了,下面這篇文章主要給大家介紹了關(guān)于在laravel 5.4中實(shí)現(xiàn)無限級(jí)分類
這篇文章主要介紹了PHP正則刪除html代碼中a標(biāo)簽并保留標(biāo)簽內(nèi)容的方法,涉及php基于正則的字符串匹配與子表達(dá)式操作相關(guān)技巧,需要的朋友可以參考下
這篇文章主要為大家詳細(xì)介紹了yii框架無限極分類的實(shí)現(xiàn)方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
這篇文章主要介紹了PHP無限極分類函數(shù)的實(shí)現(xiàn)方法,結(jié)合實(shí)例形式詳細(xì)分析了php實(shí)現(xiàn)無限極分類的具體思路、實(shí)現(xiàn)代碼與相關(guān)注意事項(xiàng),需要的朋友可以參考下
主站蜘蛛池模板: 岛国午夜 | 九九热精品视频 | 久久高清国产视频 | www.4hu影院| 国产精品夜间视频香蕉 | 天天爽夜夜爽精品视频婷婷 | 亚洲精品视频一区 | 成人在线视频免费观看 | 黄色大片在线视频 | 国产高清在线观看 | 91国内外精品自在线播放 | 欧美日韩亚洲一区 | 久久久亚洲精品视频 | 国产一区二区精 | 久久精品伊人 | 欧美a√ | 二区高清 | 国产精品激情在线 | 日韩视频国产 | 玖玖久久 | 国产精品久久在线 | 亚洲高清免费观看 | 99re在线视频精品 | 超级乱淫av片免费播放 | 成人欧美一区二区三区在线观看 | 国产片侵犯亲女视频播放 | 97色在线视频 | 欧美人妖网站 | 欧美性久久 | 国产精品一区二区视频 | 精品一区二区在线观看 | 免费视频一区二区 | 影音先锋男 | 久久香焦 | 精品国产欧美一区二区三区成人 | 日韩精品一区在线 | 日韩中文字幕一区二区 | 黄色毛片免费视频 | 日韩欧美国产不卡 | 97精品超碰一区二区三区 | 精品国产欧美一区二区 |