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.
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:
- Check whether if the current looped post is a sticky post. If this is a sticky, there’s no point of using this.
$wp_queryglobal variable and check for
$wp_query->opus_yearand set indexes based on them. If there’s no value found, set 0 as index.
- Compare the index against
date( $format, strtotime( $post->post_date ) ). The
$formatwould 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?