Creating a “Blog Page” — With Paging

If there was one question I get asked the most about WordPress themes, it’s this one: how do I make a custom static homepage at the root of my blog’s address (e.g. http://example.com/) and have my blog posts go into a /blog section (http://example.com/blog)?

WordPress is becoming more and more usable as a Content Management System, so naturally the question comes up.

But they don’t want to abandon the idea of a blog either. Blogs can be an integral part of a business website, and it makes sense that businesses and individuals would want the site and the blog managed from the same WordPress installation.

The First Option

The idea is simple … create a category called “blog” and place every single post you create in this category by making it the default category. Make all other categories “children” of the blog category.

This is actually a pretty decent option for users with a fair amount of WordPress experience. It allows you to accomplish the desired effect, and also lets you create other top-level categories for other purposes than categorizing posts (for instance, using top level categories for things like setting feature posts, press releases, or like me … theme releases).

The Second Option

The second option is a little more complicated, but is certainly a viable option for theme developers releasing themes for mass distribution (this is the option we use at iThemes. See the iCompany theme as an example.).

Here’s a step-by-step:

  1. Copy your index.php file
  2. Create a new file called blog.php and populate it with the contents of the index.php file
  3. Make it a page template by pasting the necessary code at the top. (making sure to change the template name to “Blog” instead of “Bio”)
  4. Create a new WordPress “page” (Write > Page) from your Dashboard
  5. Don’t worry about content on the page, but make the title “Blog”
  6. Before you click publish, scroll down to the “Advanced Options” and expand the “Page Template” section.  Choose “Blog” from the drop down menu.
  7. Click Publish.

Now, you’re going to want to edit the blog.php file one last time. Find “the loop“. It should look something like this:


Replace that code with this:

query('showposts=5'.'&paged='.$paged);
while ($wp_query->have_posts()) : $wp_query->the_post();
?>

You can change the “showposts=5″ to whatever number you want. It just depends on how many posts you want to be shown on a single page. Plus, but using ‘&paged=’.$paged we are able to keep paging intact … a problem that kept many people from using this method in the past.

Then, find the line of code that looks like this and remove it:


You’ll also probably want to remove any thing that has to do with not being able to find the page you were looking for. Hopefully you have a 404.php file that will take care of that for you.

Finally, after you’ve done the above, find the following code:


and change it to:


The Third Option

The final option is by far the easiest for the end user. It requires no code editing at all and accomplishes the same goal as the other 2 methods. The only problem is that it does screw up the “current_page_item” class for the home link and the blog link. Check out the possible solutions here.

Anyway, here’s how to do it.

The first thing you need to do is create a blog Page. Nothing fancy here, just write a new Page, title it “Blog”, and click “publish”. No need for any content.

Then, Assuming you’re still on the dashboard, click on Setting > Reading. Once there, you should see something that looks like this:

Default Reading Settings

Go ahead and click the radio button that says “A Static Page”. Then, you’re going to want to choose a page to use as your front page (any one of your pages will do), and you’re going to want to choose your “Blog Page” as the page to use for the posts.

Voila! You’re done! Save the settings and you should now be using one of your Pages as your homepage, and your blog Page is now housing all of your posts (and yes, paging does work with this method as well).

Conclusion

So there you go! Three different ways to accomplish the same general goal. If you have any suggestions for a better way of getting this done, feel free to leave a comment below and if it works well, then I’ll add it to the post.

Comments

  1. Murk says

    … or install WP in a subdirectory, and have a static page, or a page produced my other means, in the higher directory.

  2. Nathan Rice says

    @Murk,
    The idea is to be able to manage your entire site from within the same installation of WordPress. By moving it to another directory means you have to have 2 separate installs.

  3. Chip says

    I really like the first option, with the category “Blog”. I intend to change one of my blogs into a static web site, however I don’t want to lose the WP functionality, so I will create a “Blog” category, and everything will be listed there (there’s really not that many articles, that’s the reason).

    Thanks for the tips :)

  4. Team Nirvana says

    This is surely helpful.

    I was thinking of doing the same. So, left out my main page blank and only populated the /blog section with installation going on in it.

    Would try this for sure.

    Thanks for sharing.

  5. JamesSpratt.org says

    I go with @Murk’s suggestion. It’s what I do on my site and it works for me, I just hope it works for the average visitor too.

    And be sure to use Lester Chan’s WP-PageNavi when it comes to the pagination itself.

  6. mercime says

    Nathan, thank you for sharing the best solution for the Second Option – home.php plus blog.php. That code should definitely be in WP codex. All my previous research got me was that it could not be done, hah! I got hung up on getting the pagination to work for hours before I found your post which finally solved it. Thanks again.

  7. Douglas says

    Excellent, thanks for this post, it made my day! I used the second option. I’ve been trying to figure this one out for a while! Cheers!

  8. James says

    I don’t understand the first option. Doesn’t WordPress post all blog posts to the front page automatically, no matter which category they’re in? If that’s the case, creating new categories will organize your posts, but new posts will still be added to the home page. This wouldn’t make it static. Am I missing something?

    Thanks

  9. mikemick says

    I couldn’t figure out how to get pagination to work with WP_Query(). The &'paged='.$paged in your example is exactly what I needed. THANKS!

  10. sahithi says

    I don’t want to use wordpress to build my blog .I want them using PHP,javascript,css web technologies .how can I do that can any one assist me on that ,pls

  11. Joe says

    Thanks for the tutorial, but I don’t want to use WP for this code.

    Let me explain. WP is great, but I want to run a query from outside it to update a different website. To this end I have been trying to use wp_query() but cannot establish the long list of dependencies it needs. Does anyone know of any examples of standalone wp_query() use?

    Thanks.