WordPress.org

Ready to get started?Download WordPress

Forums

Organizing posts by category in a listing (4 posts)

  1. zszalbot
    Member
    Posted 5 years 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!

  2. zszalbot
    Member
    Posted 5 years ago #

    Thoughts anyone, please? :) Thank you!

  3. cebradesign
    Member
    Posted 4 years ago #

    Did you find an anwser for this? I'm looking for the exactly the same thing! hehe Thanks!

  4. lithy
    Member
    Posted 4 years ago #

    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!

Topic Closed

This topic has been closed to new replies.

About this Topic