WordPress.org

Ready to get started?Download WordPress

Forums

List Categories By Year (4 posts)

  1. amagonagle
    Member
    Posted 4 years ago #

    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!

  2. wprelief
    Member
    Posted 4 years ago #

    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.

  3. alchymyth
    The Sweeper & Moderator
    Posted 4 years ago #

    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(); ?>
  4. amagonagle
    Member
    Posted 4 years ago #

    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?

Topic Closed

This topic has been closed to new replies.

About this Topic