We start to work on the blog area of the site. We want to have the blog area of the site at /blog/ - so we end up making a page template for that called page-blog.php and using the Settings > Reading setting to make that page the blog homepage. This way we have very specific control over that page and what it shows. In that template, we use a custom WP_Query loop to give us exactly what we want.

We decide that /blog/ should show the entirety of the most recent blog post. That makes sense for what the user has clicked from the homepage (a big button that says LATEST WRITING: Name of Blog Post). Later we'll deal with how to handle the archives.

Speaking of the homepage, we use pretty much the same query/loop on the home.php template to get that most recent blog post name.


  1. Patrick Moore
    Permalink to comment#

    Aren’t you supposed to reset the query after using WP_Query()? Or does it matter if you are only using it once on a page?

    • Chris Coyier
      Permalink to comment#

      I don’t think it matters. WP_Query doesn’t affect the default query on the page. It would matter if we used query_posts. Although it’s funny, in the Codex for WP_Query, their examples DO reset the query. But… they even say right before it it doesn’t matter.

      /* Restore original Post Data 
       * NB: Because we are using new WP_Query we aren't stomping on the 
       * original $wp_query and it does not need to be reset.
  2. Ricky55
    Permalink to comment#

    Why was the blog even necessary when it was just showing a single post anyway?

    The home page nav could just bring in the latest post and link to the permalink and just use the single.php template to display it. I’m new to WP so I’m may be missing something.

    Great series though.


    • Chris Coyier
      Permalink to comment#

      That’s certainly a possibility. The main difference right now is that the /blog/ page doesn’t list out all the comments. In the future /blog/ could be used to display multiple blog posts instead of just one. It turned out to be useful as it was, as a target for ajax to pull in the latest post only, but that could easily be updated.

Leave a Comment

Posting Code

We highly encourage you to post problematic HTML/CSS/JavaScript over on CodePen and include the link in your post. It's much easier to see, understand, and help with when you do that.

Markdown is supported, so you can write inline code like `<div>this</div>` or multiline blocks of code in in triple backtick fences like this:

  function example() {
    element.innerHTML = "<div>code</div>";

We have a pretty good* newsletter.