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.