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. User Avatar
    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?

    • User Avatar
      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. User Avatar
    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.


    • User Avatar
      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!

You may write comments in Markdown. This makes code easy to post, as you can write inline code like `<div>this</div>` or multiline blocks of code in triple backtick fences (```) with double new lines before and after.

Code of Conduct

Absolutely anyone is welcome to submit a comment here. But not all comments will be posted. Think of it like writing a letter to the editor. All submitted comments will be read, but not all published. Published comments will be on-topic, helpful, and further the discussion or debate.

Want to tell us something privately?

Feel free to use our contact form. That's a great place to let us know about typos or anything off-topic.