zszalbot
Member
Posted 10 months ago #
Hello,
I have a page where I display all posts within a category (it also includes subcategory). I would like to break down the listing like this:
sucategory-title:
- post
- post
another-subcategory-title:
- post
- post
I currently have it like this:
- post
- post
- post
- post
Is there a way to display both the subcategory title and posts which fall into the given subcategory?
Thanks!
zszalbot
Member
Posted 10 months ago #
Thoughts anyone, please? :) Thank you!
cebradesign
Member
Posted 5 months ago #
Did you find an anwser for this? I'm looking for the exactly the same thing! hehe Thanks!
There is a plugin called Latest Post By Category that does something similar to this
if (is_category()) {
$this_category = get_category($cat);
}
if ($this_category->category_parent) {
$child_categories = get_categories('child_of=' . $this_category->cat_id);
foreach ($child_categories as $child_category) {
$my_posts = get_posts('orderby=menu_order&order=ASC&cat=' . $child_category->cat_id);
foreach ($my_posts as $post) : the_post()
?>
<div class="post">
<?php the_title(); ?>
</div>
<?php endforeach; ?>
<?php } ?>
<?php } ?>
That code doesn't quite work...but maybe it's on the right track? Any ideas?
Thanks!