This week at school has been far, far too busy. I did get one thing done, though. I finally figured out how to make WordPress generate both a static home page, and a page with my recent blog posts. I had one more condition that made this task surprisingly difficult- I didn’t want to put my blog into a subdirectory, or add anything to my URL hierarchy.

The Easy Part

Making a static home page is simple. You can download one of the many plug-ins that let you make a WordPress page load as your home page. Or, if you’re feeling a bit more adventurous, you could change your index.php into a static page. Either way, it’s not too big of a hassle. Unfortunately, you’ll also be left without a page that indexes your most recent blog posts (as the home page does by default in WP).

The Hard Part

One would think that making a copy of index.php, and using that copy as the template for a page would make that page display the most recent blog posts, as index.php does by default. One would be horribly, horribly wrong. I made a copy of my index.php, and called it blog.php. At the very top of my blog.php, I added the following:

< ?php /* Template Name: blog */ ?>

Then, I created a page called test index, and selected the “blog” template for it. Here are the results:

test index

Not very impressive, is it? The thing didn’t even load a single post. It took me hours of digging through WordPress documentation before I finally found out what was wrong. There are certain ways in which WordPress treats calls to index.php or home.php differently than any other php files. In order to create a page that lists an index of blog entries, it’s necessary to set a global variable called $more=0. It’s this sort of random surprise, completely obfuscated from any of the files which seem to have any bearing on the task at hand, that makes working on WP a pain sometimes. After finally figuring out this one vital piece, making a WP page generate an index of my most recent posts was easy. I name the page index, and that’s the page you’ll see if you click on my header graphic.

A Working Index Template

Here’s the basic template to use to generate a blog index from a WordPress Page:

< ?php /* Template Name: blog */ ?>

< ?php $more=0; query_posts('showposts=10'); ; get_header(); ?>

< ?php if (have_posts()) : ?>
< ?php while (have_posts()) : the_post(); ?>
YOUR CODE TO DISPLAY POSTS HERE
< ?php endwhile; ?>
< ?php endif; ?>

< ?php get_sidebar(); ?>

< ?php get_footer(); ?>

A basic template is here.

After saving that template in the directory for your theme, it’s just a matter of making a page in WP, and choosing the “blog” template. Voila! A blog post index from a page.