How I Bent Wordpress to My Will ( and made a page act as a blog post index )
November 18th, 2006 by MarkThis 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:
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.
:

November 19th, 2006 at 12:14 pm
great job, though I didn’t understand a single word after ‘This week at school has been far, far too busy’.
December 6th, 2006 at 7:38 pm
[...] This test page is run by wordpress, a fine system, much clearer than the former primary candidate joomla, apart from one tiny little problem: the installation of a fixed entry page. All the approaches available out there I have tested seem rather like sort of a hack than a clean solution (Update: maybe I test some more:1, 2). Therefore, I will probably test a few of its contenders during the next days. This blog entry serves as a note list, if you have any further suggestions please let me know. My requirements: a free lightweight CMS or extended blog system, easy to adapt and to manage. [...]
January 23rd, 2007 at 11:20 pm
[...] any page to be their home page, and display a list of their posts on any other page. I personally spent hours figuring out how to code around the lack of this feature several months ago. Now, it’s [...]