Creating A Blog Page That Works With Home.php
If you’re like me, you probably use Wordpress for more than just a blog. I build fully functioning sites with Wordpress because its easy for me to show clients how to update their own information within pages and they need no knowledge of HTML, CSS, or PHP. If this is the case, you’ll probably want to take advantage of the home.php file if you haven’t already.
If you put a home.php file in your themes directory, this will automatically become your blogs homepage (overriding the index.php file). This is a great way to use wordpress for more than just blogging, whether it be your company homepage with information, or just a page with some of your featured content that you’d like to highlight to visitors when they first arrive. Many people will say that you can use the built in admin panel option of using a static page as your homepage. This is true, but it lacks the ability to add php code and be completely customizable like the home.php file is.
There is a small probably with the home.php file however. If you make your homepage different than the good ole’ latest posts in reverse chronoligical order, you’ll probably want to put that page somewhere else. Most likely in yourdomain.com/blog/ or something similar. Well its not as hard as you might think, just takes a quick little template trick and you’ll be on your way in no time.
First, create a new php file, and enter the following and save it (blog.php should work well for that) – this is creating a page template named “Blog” and using the index.php file to complete it.
<?php
/*
Template Name: Blog
*/
// Which page of the blog are we on?
$paged = get_query_var('paged');
query_posts('cat=-0&paged='.$paged);
// make posts print only the first part with a link to rest of the post.
global $more;
$more = 0;
//load index to show blog
load_template(TEMPLATEPATH . '/index.php');
?>
Now that you’ve created, saved, and uploaded blog.php to your theme directory, you’re on to the last step.
Go to Add New Page, create a blank page with the title “Blog” (or whatever you’d like it to be).
In the right column underneath the publish button, you’ll see an attributes section, with a “Template” pulldown. From this pulldown select “Blog”.
Press the Publish button, and you should be good to go, and yourdomain.com/blog/ should list all your recent posts as the index.php page does.






User Comments
Post Comment