如何让WordPress分类归档排除子分类文章

  • 时间:2020-05-29 14:26:07
  • 分类:网络文摘
  • 阅读:153 次

wordpress默认会在分类列表中显示子分类文章,如果只想显示该分类的文章,而不显示子分类中的文章,这里介绍一个wordpress技巧,可以通过以下代码来实现。

在wordrpress主题的文章归档模板文件(通常是archive.php)中找到主循环代码:

  1. <?php while ( have_posts() ) : the_post(); ?>
  2. <?php endwhile; ?>

在其上添加代码:

  1. <?php query_posts(array('category__in' => array(get_query_var('cat')))); ?>

在其下添加代码:

  1. <?php wp_reset_query(); ?>

原文:http://zmingcx.com/wordpress-classification-archive-subcategories.html

推荐阅读:
Prepare All Keyboard Warriors: A TikTok and Twitter Merger is Ab  Content Creation Platforms That Pay in Crypto  How to be like Elon Musk: An Influencer CEO  Your Simple Guide to Ultimate Technology Stack Every Blogger Nee  Recursive Algorithm to Encrypte a String  Reconnect the Nodes in Linked List by Odd/Even in Place (Odd Eve  Breadth First Search Algorithm to Find Nearest Right Node in Bin  Using Priority Queue to Compute the Slow Sums using Greedy Algor  Min Number of Operations to Crawler Log Folder  Reclaiming the Disk Space by Deleting the Logs of the Docker Con 
评论列表
添加评论