Title: Remove First Month
Last modified: August 19, 2016

---

# Remove First Month

 *  Resolved [fear26700](https://wordpress.org/support/users/fear26700/)
 * (@fear26700)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/remove-first-month/)
 * Hello fellow WordPress forum members!
 * I have a PHP script I’m using to display a list of all posts in an archive, and
   dividing the list into months, but I would really like to know how can I remove
   the first month from rendering with PHP. Here is my current code:
 *     ```
       <?php
       $prev_date = NULL;
       $date = NULL;
       ?>
       <?php query_posts("posts_per_page=-1&order=DESC"); ?>
       <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
       <?php
       $date  = get_the_time('m.Y');
       if($date != $prev_date)
       {
       $prev_date = $date;
       echo "<li class='month'>";
       echo get_the_time('F');
       echo "</li>";
       }
       ?>
       ```
   
 * At this moment, and for the time being, I’m using CSS3 to hide the first child
   element with a class of “month”, since individual months get a class of “month”,
   but I would like to remove the markup all together.
 * Thanks in advanced!

Viewing 5 replies - 1 through 5 (of 5 total)

 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/remove-first-month/#post-1502766)
 * Since you didn’t really explain what first month means, check the Time Parameters
   section of the query posts article.
 * [query_posts()](http://codex.wordpress.org/Template_Tags/query_posts)
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/remove-first-month/#post-1502773)
 * this could work:
 *     ```
       if($date != $prev_date)
       {
         if($prev_date != NULL)
         {
         echo "<li class='month'>";
         echo get_the_time('F');
         echo "</li>";
         }
       $prev_date = $date;
       }
       ```
   
 *  Thread Starter [fear26700](https://wordpress.org/support/users/fear26700/)
 * (@fear26700)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/remove-first-month/#post-1502828)
 * alchymyth,
 * I don’t know how that works, but it works! haha. Thanks a lot!
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/remove-first-month/#post-1502832)
 * you want to know?
 * – when you start off, the $prev_date is set to NULL;
    – you get the first result
   from the query; – you go to the first if statement for the first time; and the
   result is obviously that the $date is already set to something, while $prev_date
   is still NULL; you go to the second if statement for the first time; and $prev_date
   is still NULL, so the if is false and does not do the thing in the brackets (
   i.e. it is skipping your first date); – then you set $prev_date equal to $date;–
   next round, $prev_date is not NULL anymore …
 *  Thread Starter [fear26700](https://wordpress.org/support/users/fear26700/)
 * (@fear26700)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/remove-first-month/#post-1502835)
 * Interesting…thanks again alchymyth

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Remove First Month’ is closed to new replies.

## Tags

 * [month](https://wordpress.org/support/topic-tag/month/)
 * [php](https://wordpress.org/support/topic-tag/php/)
 * [remove](https://wordpress.org/support/topic-tag/remove/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 5 replies
 * 3 participants
 * Last reply from: [fear26700](https://wordpress.org/support/users/fear26700/)
 * Last activity: [16 years, 3 months ago](https://wordpress.org/support/topic/remove-first-month/#post-1502835)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
