• I’m looking for a way to display posts from categories by year. Is this possible? For example I want to show posts in the category January/February and then by year, so 2009, 2010 etc. So the link would be “January/February 2009”, “January/February 2010” etc. I currently have posts in the category of January/February. Can I just assign the relative posts to that category (January/February) or would I need to create each year as a category? If someone has a better solution please let me know. Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Are your january/February categories based on the post date?

    You could always do a custom query against the post date and display the posts in that way.

    the code below shows al posts of the ‘jan/feb’ category, and shows the year in places where it changed from the year before:

    <?php // category by year/
    
    $args = array(
    'posts_per_page' => -1, // show all posts
    'category_name' => 'january/february'
    );
    
    query_posts($args);
    
    	 if (have_posts()) : while (have_posts()) : the_post(); ?>
    
    		<?php if ($year!=get_the_time('Y')) { $year = get_the_time('Y'); echo '<div class="archive_year">'.$year.'</div>'; } ?>
    		<div class="post">
    		<h3><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
    		<div class="archive_excerpt">
    		<?php the_excerpt(); ?>
    		</div>
                      </div>
    
    	<?php endwhile; endif; wp_reset_query(); ?>
    Thread Starter amagonagle

    (@amagonagle)

    Excellent! Thank you!

    How can I modify this if I want to add:

    March/April
    May/June
    July/August
    Sept/October
    Nov/Dec

    Could I add the category ID for the additional months in the array?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘List Categories By Year’ is closed to new replies.