Display Child Category Posts Only
-
Hi,
I’m trying to display a list of posts at the top of each category page. I’ve figured out how to make that happen, at least in a rough form, but I’m running into the problem that it’s displaying parent category posts even at deeper levels.
Here is the code that I am using, in my category.php file:
<?php global $post; $categories = get_the_category(); $category = $categories[0]; $cat_ID = $category->cat_ID; $myposts = get_posts("numberposts=20&category=$cat_ID"); ?> <?php foreach($myposts as $post) :?> <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> <?php endforeach; ?>Here is an example of the problem. On this page, I would like to only see posts relating to “burgers” where now I get the last 20 food related posts from the entire parent category “eat.”
http://www.tacomamama.com/v2/?cat=93
I’d be extremely grateful for any help you can provide. Please let me know if I can provide any more examples.
The topic ‘Display Child Category Posts Only’ is closed to new replies.