Organize WordPress Category Archive Listing by Subcategory

/ Published in: PHP
Save to your folder(s)

This code replaces a normal category template. It sorts all posts by their category/subcategory instead of bunching them all together and ordering them by date. A bit complicated to explain in a box this size... Check the link for a run through!

Copy this code and paste it in your HTML
  1. <?php $categories = get_categories("child_of=17"); foreach ($categories as $cat) { ?>
  2. <div class="genre_subcat">
  3. <?php query_posts("cat=$cat->cat_ID&showposts=-1&order=ASC&orderby=name"); ?>
  4. <h2><?php single_cat_title(); ?></h2>
  5. <small><?php echo category_description($cat->cat_ID); ?></small>
  6. <?php while (have_posts()) : the_post(); ?>
  7. <div class="post">
  8. <h3><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to
  9. <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
  10. <p class="postdate"><?php the_time('F jS, Y') ?></p>
  11. <?php the_content(); ?>
  12. <p class="postmetadata">Posted in <?php the_category(', ') ?> |
  13. <?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?></p>
  14. </div>
  15. <?php endwhile; ?>
  16. </div>
  17. <?php }?>


Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.