WordPress教程

WordPress分类页面如何只显示置顶的文章

阿里云

本文讲的是 WordPress 分类页面如何只显示置顶的文章,而不是显示置顶文章在最上面哦。

可将以下代码加入到主题的 functions.php 最后面:

也想出现在这里?联系我们
创客主机
  1. /**
  2. * Category Archives: Only display sticky posts for each category term
  3. */
  4. add_action( 'pre_get_posts', function( \WP_Query $q )
  5. {
  6. if( ! is_admin() && $q->is_category() && $q->is_main_query() )
  7. {
  8. $sticky_posts = get_option( 'sticky_posts' );
  9. if( ! empty( $sticky_posts ) )
  10. $q->set( 'post__in', (array) $sticky_posts );
  11. }
  12. } );

WordPress 分类页面如何只显示置顶的文章

已有 146 人购买
查看演示升级 VIP立刻购买

收藏
(0)

发表回复

热销模板

Ashade - 作品展示摄影相册WordPress汉化主题
LensNews

本站承接 WordPress / PbootCMS / DedeCMS 等
系统建站、仿站、开发、定制等业务!