#85: Blog Post View (single.php) in WordPress

(Updated on )

If we had to pick, the view for a single blog post is probably the most important template on the site. We have a static mockup of a blog post page, so we work on moving it over into WordPress.

The grid is slightly different. It uses our super easy grid structure and classes, only instead of the 1/2, 1/4, 1/4 structure on the homepage it uses a 2/3, 1/3 structure. No big deal, just different class names.

We finally take the time to figure out the correct semantic structure for the <time> element. The content inside can be anything, but the attributes on the time element have to be in a specific format. I’m all about doing this correctly to help with anything out there that might be crawling/reading the site and looking for proper machine readable information like this. Ultimately the format differs slightly and we end up with:

<time datetime="<?php the_time('Y-m-d'); ?>">
  <?php the_date(); ?>

The format for the_date() is controlled by settings in WordPress. I like leaving that stuff alone instead of forcing a format onto it. Control FTW!

Because the sidebar.php file is included in several different pages and sometimes the grid it is included on differs from page to page, we set up a simple system where we set a variable before we call the sidebar that instructs it on how wide it should be. We have to debug it a little bit, of course, because sometimes this programming stuff is vexing. Ultimately we have to reference it as a $GLOBALS['sidebarWidth'] which I’m sure is a bit janky, but not too concerning since this is such a simple site, development wise, with a team of one.