Posted By

kristarella on 05/21/09


Tagged

wordpress thesis thesiswp


Versions (?)

Who likes this?

6 people have marked this snippet as a favorite

mlangfeld
tobiasmay
girliegeek
joelhaus
booski
naeemnur


Archives listing posts by category


 / Published in: PHP
 

URL: http://www.z-oc.com/blog/2008/03/category-based-archive/

This used to be code adapted from Z'Oc, but I decided to start again and write it fresh with WPQuery instead of getposts.

  1. function custom_archives_template() {
  2. $cats = get_categories("hierarchical=0");
  3. if ($cats) :
  4. echo '<h2>By Category:</h2>';
  5. foreach ($cats as $cat) :
  6. $cat_name = $cat->cat_name;
  7. $cat_id = $cat->cat_ID;
  8. $cat_link = get_category_link($cat_id);
  9.  
  10. echo '<ul>';
  11. echo ' <li class="cat_name"><h3>' . $cat_name . ' <span class="count">' . $cat->category_count . '</span></h3>';
  12. $catposts = new WP_Query("showposts=-1&cat=$cat_id");
  13. if ($catposts) :
  14. echo ' <ul>';
  15. while ($catposts->have_posts()) : $catposts->the_post();
  16. echo ' <li><a href="' . get_permalink() . '">' . get_the_title() . '</a> <span>' . get_the_time('j F Y') . '</span></li>';
  17. endwhile;
  18. echo ' </ul>';
  19. endif;
  20. echo ' </li>';
  21. echo '</ul>';
  22.  
  23. endforeach;
  24. endif;
  25. }
  26. remove_action('thesis_hook_archives_template', 'thesis_archives_template');
  27. add_action('thesis_hook_archives_template', 'custom_archives_template');

Report this snippet  

You need to login to post a comment.