I was wondering if there was any way to make a custom loop that divides posts into months. I would use it on the Archive page to list all posts within a given category with a title that indicated what month it was posted.

Like this:


post1 post2 post3


post4 post5 post6

Any help would be appreciated. Thanks!

1 Answer 1


you could do this in any loop by checking the current post's published month, and printing it when it changes:

// set current month to that of first post, and print it.
$current_month = get_the_time('F');
echo $current_month;

while (have_posts()) : the_post();

    // check each subsequent post to see if the month is the same
    // or has changed and needs to be printed:
    $this_month = get_the_time('F');
    if( $this_month!=$current_month ):
        $current_month = $this_month;
        echo $current_month;

    // output data for the post



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.