$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>customization - How can I get posts in a subcategory to display on it's parent categories archive page?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

customization - How can I get posts in a subcategory to display on it's parent categories archive page?

matteradmin10PV0评论

Currently when you display an archive category page, it only displays it for the main parent, and doesn't display any of the posts that may be in the subcategories under it's parent.

How can I alter it so that for every category archive it will display all posts under it, including the subcategory posts?

Currently when you display an archive category page, it only displays it for the main parent, and doesn't display any of the posts that may be in the subcategories under it's parent.

How can I alter it so that for every category archive it will display all posts under it, including the subcategory posts?

Share Improve this question edited Dec 16, 2013 at 17:48 Krzysiek Dróżdż 25.6k9 gold badges53 silver badges74 bronze badges asked Aug 27, 2010 at 17:04 HeroicNateHeroicNate 4
  • @HeroicNate: Are you sure subcategories do not already appear? In my testing on a vanilla Wp 3.0.1 site they do. Maybe you've got a plugin that's disabling them? Or maybe I misunderstand your question? – MikeSchinkel Commented Aug 27, 2010 at 18:00
  • Yes I'm sure. Lets say there is a category "News" and it has subcategories "Sub News 1" and "Sub News 2". If you go to www.blog/category/news you will only see what was posted in "News", but not in the subcategories unless those posts also have the "News" category checked. Currently the only way to see the sub categories would be to go to www.blog/category/sub-news-1 – HeroicNate Commented Aug 27, 2010 at 18:06
  • this is the same no matter what theme i use. – HeroicNate Commented Aug 27, 2010 at 18:08
  • Okay, I went ahead and added an "answer" so I could show screenshots. – MikeSchinkel Commented Aug 28, 2010 at 3:21
Add a comment  | 

2 Answers 2

Reset to default 1

I ran another test and unless I'm loosing my mind child categories are definitely displayed on the category archive page in WordPress v3.0.1 (is that the version you are running, or are you on an earlier version?)

Here are two screenshots, the first showing the category layout for my test install:


(source: mikeschinkel)

The next screenshots is the category archive page for my test install showing three posts, each with one category selected; the Parent, the Child and the Grandchild category, respectively.:


(source: mikeschinkel)

So I'm 95% certain you have a plugin or some other code that is disabling your subcategories from displaying on your archive page. Can you add the list of plugins you are using to your question content?

The relation between category and subcategory does not matter when you display a category because only one category (and not two or three like one main category and two subcategories) will be displayed.

So you need to override the query. I know that this should be possible via filtering a wp_query hook (hook in, get all child cats, add them to the query arguments) but I can't tell you this out of my head with some sample code. But maybe this little info is already helpful.

The question indeed is nice for drill-down style content sites.

Post a comment

comment list (0)

  1. No comments so far