Grow your CSS skills. Land your dream job.

Group query_posts results by month?

  • # November 24, 2012 at 6:38 am

    Hi,

    So I’m working on the archive section for a WordPress blog, and am using query_posts to display all the posts and also using some pagination. However I’d like to show the posts grouped by month. So like :

    September 2012:
    - Post 1
    - Post 2

    August 2012
    - Post 1
    - Post 2

    Etc.

    Here’s the code I’m using : (The list is there 2 times because as you may see I’ve added the functionality of switching between an image viewer and a list viewer.)

    < ?php query_posts('&posts_per_page=18'); ?>

      “>< ?php the_title(); ?>

      < ?php the_time(get_option('date_format')); ?>

      …< ?php echo substr(strip_tags(get_the_content($post->ID)), 0, 200); ?>…

      < ?php endwhile; endif; ?>

      < ?php if(have_posts()) : while ( have_posts() ) : the_post(); ?>

    • ” class=”overlay-btn”>

      < ?php the_title(); ?>

      < ?php the_post_thumbnail(array('154', '999')); ?>

    • < ?php endwhile; endif; ?>

    Anyone have any ideas of how to group the results by the month they were published?
    Thanks in advance :)

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".