• Resolved csleh

    (@csleh)


    On the category page, I need to list all subcategories with post excerpts in that subcategory. I’m trying to do this without specifying subcategory id’s, so that new subcategories will automatically show.

    I’ve tried all sorts of code, but I can either:
    – show a list of subcategories (no posts)
    OR
    – show all posts, but it repeats the subcategory name above each post, which is confusing.

    The ideal looks like this, when on the category page (using category.php):

    Fruit Category Page
    apples (a subcategory of fruit)
    – apple post one excerpt
    – apple post two excerpt
    bananas (a subcategory of fruit)
    – banana post excerpt
    etc.

    I can specify the category id, but want the subcategories to list without having to put in id’s.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Here’s a snippet of code that I had to use recently. It might help you. What it does is it pulls up all the children of a particular category, links to an archive for only that category and it’s posts, and then also queries posts for each child category. If that makes sense…

    Here’s all the code

    <?php $categories = get_categories("child_of=5"); foreach
            ($categories as $cat) { ?>
    	<?php query_posts("cat=$cat->cat_ID&showposts=10
            &order=ASC&orderby=name"); ?>
    	<h2><a href="<?php  echo get_category_link($cat->cat_ID) ?>">
            <?php single_cat_title(); ?></a></h2>
    	<small><?php echo category_description($cat->cat_ID); ?></small>
    
            <?php while (have_posts()) : the_post(); ?>
    	<a href="<?php echo get_permalink() ?>" rel="bookmark"
            title="Permanent Link: <?php the_title(); ?>"><?php the_title(); ?>
            </a> <?php endwhile; ?>
    <?php }?>

    If you don’t want the child category to link to it’s own page you can pare it down some like this:

    <?php $categories = get_categories("child_of=5"); foreach
            ($categories as $cat) { ?>
    	<?php query_posts("cat=$cat->cat_ID&showposts=10
            &order=ASC&orderby=name"); ?>
    	<h2><?php single_cat_title(); ?></h2>
    
            <?php while (have_posts()) : the_post(); ?>
    	<a href="<?php echo get_permalink() ?>" rel="bookmark"
            title="Permanent Link: <?php the_title(); ?>"><?php the_title(); ?>
            </a><br />
         <?php the_excerpt; ?>
          <?php endwhile; ?><?php }?>

    Of course that’s to pull up children of a specific category. But that should be close to what you need.

    Thread Starter csleh

    (@csleh)

    Thank you!

    All current and future categories need to be children of 3 because of the navigation and structure. Now that works perfectly.

    I’ve got this code on the category-3.php page, and regular category listing on category.php. Probably be easier with one template and an if/else statement, but time to move on to the next puzzle.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘listing with excerpts and subcategory title’ is closed to new replies.