25/06/2017

The archive contains older posts which may no longer reflect my current views.

# The previous/next day links are in.

It took a bit of fiddling (I'm sure there's probably an easier way to achieve it) but I got there after a bit of trial and error - mostly error ;)

The is_day() function returns true if you are on an archive page showing posts for a day. This makes it nice and easy to isolate day views.

I needed to get the date for the day being viewed, so I could build the links for date +/-1, and pulled this from the WordPress query:

$year     = get_query_var('year');
$monthnum = get_query_var('monthnum');
$day      = get_query_var('day');

This was combined into a single string which was then converted to a date:

$archive_str = $year . '/' . $monthnum . '/' . $day;
$archive_date = strtotime($archive_str);

The strtotime() function is really handy and lets you do relative calculations; getting +/-1 day is simple and these new dates were formatted according to the WordPress archive URL structure making it easy to build the links:

$previous = strtotime('-1 day', $archive_date);
$next = strtotime('+1 day', $archive_date);
$previous = date('Y/m/d', $previous);
$next = date('Y/m/d', $next);

The Today page is, obviously, a little different in that it is not an archive. What I've done here is create one link for 'yesterday' calculated from whatever the day 'today' happens to be:

$today = time();
$yesterday = strtotime('-1 day', $today);
$yesterday = date('Y/m/d', $yesterday);

I have a check elsewhere that sets a variable based on whether there are any posts for 'today' so repurpose this to only show the 'yesterday' link if that is true.

# I think next up is to add a header to day pages like 'Today' with the date and number of posts.

Sonant Thoughts - Episode 30: Opening Up


Our websites are the little parts of the internet that we own and control and, especially when they are personal, they should reflect who we are.

Rather than be quite so focused I want the blog to become more of a personal reflection, to take on a personality alongside the more 'tech' bits I normally write.


Subscribe: via RSS or iTunes

Sonant Thoughts

# The headers are now in on the day pages with the date, post count and downwards visual indicator just as on the 'Today' page. Helps to bring it all together for a more consistent experience.