WordPresss是全球最受歡迎的蓋站程序,所以很多網絡營銷從業者都用WordPress建立站做網絡推廣。
- WordPress置頂文章通常僅顯示在首頁上,類別存檔頁面不顯示置頂文章。
- 有更多豐富內容的網站,會用置頂文章來作為推薦文章。
- 以便訪問者可以查看網站的推薦內容。
如果類別列表顯示網站上的所有置頂文章,它顯然會影響用戶體驗,因此只顯示該類別中的置頂推薦文章更友好。
WordPress分類頁面調用當前分類置頂文章方法
如果要在類別存檔頁面上,調用當前分類的置頂文章,可以使用陳溈亮在本文中分享的方法。

將以下代碼添加到主題archive.php,或category.php模板的主循環上方 ▼
<?php
query_posts(array(
"category__in" => array(get_query_var("cat")),
"post__in" => get_option("sticky_posts"),
'showposts' => 3,
)
);
while(have_posts()) : the_post();
?>
<h1>置顶<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h1>
<?php
endwhile;
wp_reset_query();
?>翻譯:'showposts'=> 3,是顯示的數量。
從常規文章列表中排除已經置頂的文章▼
<?php while(have_posts()) : the_post(); ?>
<?php if(!is_sticky()){?>
<h2><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
<?php the_excerpt(); ?>
<?php } endwhile;?>如果你想讓WordPress分類/標籤/作者頁顯示置頂文章,請點擊查看以下建站教程▼
希望陳溈亮博客( https://www.chenweiliang.com/ ) 分享的《WordPress分類歸檔頁面如何調用當前分類置頂文章? 》,對您有幫助。
歡迎分享本文鏈接:https://www.chenweiliang.com/cwl-982.html