WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to show all posts posted under the month, so



post 1
post 2


post 1
post 2

The posts are to appear under my custom taxonomy template, so taxonomy-pubyear.php and I'm able to retrive all the posts for that term using the basic loop. If I add get_the_year('F') in the loop then the same month will be displayed repeatedly but I need it displayed once and have all the corresponding posts show up under it, any help with this would be appreciated.

Note: If I have post published under the same day, month and year then the above get_the_year('F') will show the month and display those posts below it, i want that functionality but without having to use the same published date.

share|improve this question
up vote 1 down vote accepted

Save the current month in a variable and check it for each post, only output it when it changes:

$current_month = '';

while( have_posts() ):

    $this_month = get_the_time( 'F' );

    if( $this_month != $current_month ){
        $current_month = $this_month;
        echo $current_month;


share|improve this answer
That worked! Thanks a million. Just out of curiosity, why not use the get_the_date() function instead? – Beto Jan 17 '13 at 3:30
you could use get_the_date here, it would work the same. I'm in the habit of using get_the_time because it's a bit more flexible, as you can also pass a post id where get_the_date will only work with the global $post object. – Milo Jan 17 '13 at 3:57
Thanks for your input. – Beto Jan 18 '13 at 8:00

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.