• 首页
  • 渗透
  • 折腾
  • 转载
  • 关于Me
  • 榜上有名
  • 文章存档
  • 友情链接

不妨看看这里

会员面板

Base64 Image

WordPress 自定义类型文章在首页和搜索页展示

  • Mr.Wu
  • 2017-12-23
  • 0
表示如果不让自定义类型文章在首页展示的话,博客的文章量真的很寒碜,尽管我已经很努力的写文章了。。。 将以下代码添加到主题的functions.php中:
//自定义类型文章在首页和搜索页展示
if ( (is_home() || is_search()) && $query->is_main_query() )
 $query->set( 'post_type', array('post', 'product' ) ); //只显示product
 // $query->set( 'post_type', array( 'shuoshuo', 'product' ) ); //主循环中显示shuoshuo和product
 return $query;
}
add_action('pre_get_posts','ashuwp_posts_per_page');
pre_get_posts钩子,不光可以实现这一点,你还可以自由发挥,改变主循环的其它一些参数,具体请查阅官方函数说明。
© 2025 MrWu
Theme by Wing-child
  • {{ item.name }}
  • {{ item.name }}