This is a trick I used on Opus Theme: creating a year / month / date separator between posts if the current and the next post happen to have different year / month / date.

date only separator
date only separator
month and date separator
month and date separator
year, month and date separator
year, month and date separator

The aim of this element is to make a clear distinction between posts which is published on different year / month / date. I personally think that this distinction will be useful if you are using one column layout theme, post a lot, and using infinite scroll (which is pretty much what I do). This separator notifies your reader that they are scrolling and moving to different time span1.

This is what I did to create the separator. This snippet should be placed inside the loop, preferably before displaying article through get_template_part( 'content', get_post_format() );:

Disclaimer: this code I pasted directly from Opus Theme. These are what the code above does:

  1. Check whether if the current looped post is a sticky post. If this is a sticky, there’s no point of using this.
  2. Get $wp_query global variable and check for $wp_query->opus_date, $wp_query->opus_month, and $wp_query->opus_year and set indexes based on them. If there’s no value found, set 0 as index.
  3. Compare the index against date( $format, strtotime( $post->post_date ) ). The $format would be the shortest numeric-only version of date, month and year. If the indexes are bigger than 02 and aren’t equal to date( $format, strtotime( $post->post_date ) ), display the separator.

Pretty neat, don’t you think?


  1. be it day, month, or year 

  2. since we wouldn’t want to display date, month, and year separator at the top of very first post 

One thought on “Create Year / Month / Date Separator Between Posts

  1. I’m using your Materialist theme, which does something like this, but I wanted the separator to happen every day, so I swapped this code in hentry-separator file. It works great, with one exception. With autoscroll on, when you scroll to a new page, the date is repeated, so if I have a lot of posts today, as I scroll through pages, the same date is repeated over and over as the pages change. Any way to prevent that from happening?

Share Your Thought