Display category posts sorted by year in sidebar, need help with code
-
With help of this support forum I managed to group posts in my sidebar from the category “photoalbum”. I would like to however group them by year, so that e.g. the albums from 2004 are under 2004, 2003 under 2003. I can of course copy the code below for each year but I figured out there might be a smarter way of doing that… I am however not a php guru and I would not know how this would go… can somebody please enlighten me:-) Many thanks in advance!
The code:
<li><h2><?php _e('2005'); ?></h2>
<ul>
<?php $temp_query = $wp_query; ?>
<?php query_posts('category_name=photoalbum&year=2005&orderby=date&showposts=-1'); ?>
<?php while (have_posts()) : the_post(); ?>
<id="post-<?php the_ID(); ?>">
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">
<?php the_title(); ?><br></a>
<?php endwhile; ?>
<?php $wp_query = $temp_query; ?>
</ul>
</li>
- The topic ‘Display category posts sorted by year in sidebar, need help with code’ is closed to new replies.