Creating a Custom Blog Homepage [Wordpress]
Wordpress is extremely customizable and that’s one of the beauties of it. When you are able to master customizing blog themes for Wordpress, you can turn the platform into almost anything.
The problem is that most people don’t know how to do it. They look at a blog theme and see nothing but cryptic HTML and PHP code. Sound familiar?
Last week, I was told about the confusions a person was having on creating a custom blog homepage (like what I have here on DavidRisley.com). They couldn’t find anything on the net to show them how to do it. He was trying to use a Wordpress page to do it. He tried using plug-ins. Nothing worked to create a dynamic homepage.
It is actually much easier than any of that. I’ll show you how.
Create a Custom Homepage File in Your WP Theme
If you view the template hierarchy for Wordpress, you’ll see the order for which it checks for files in your theme. In the image on that page, you’ll see home.php. It will check for this file and, if it doesn’t find it, it will default to your index.php file.
So, go into the folder where your theme is located. It will be in /wp-content/themes/[name of theme]/. You will see an index.php file there. Now, you might find a home.php file in there. THAT is your homepage template. If your theme doesn’t have a home.php file, just create one. Create a copy of your index.php file and simply save it as home.php. From there, the file will need to be modified.
I hope I haven’t lost you.
Essentially, any theme changes you make to the home.php file will only affect your blog’s homepage. So, within this file, we will make any changes to make your blog homepage look like you want it to look.
Showing a Feature Post
On the homepage of this blog, I show a single feature post for the day at the top. How did I do that?
I created a category called “Feature”. Whenever a post is assigned to this category, it is made into a feature. I also assign the post to whatever other categories are relevant.
Here is the code to output the feature:
<?php $my_query = new WP_Query(’category_name=feature&showposts=1′); while ($my_query->have_posts()) : $my_query->the_post(); $do_not_duplicate = $post->ID; ?>
<h6>Today’s Feature Post</h6>
<div class="clearboth"></div>
<div class="comm"><span><?php comments_popup_link(’0′, ‘1′, ‘% ‘); ?></span></div>
<h3 class="h1" id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h3>
<div class="post-meta-top">
<div class="date"><span><strong><?php the_time(’F j, Y’); ?></strong></span></div>
</div>
<div class="clearboth"></div>
<?php the_content(’<br />Read the rest of this entry »’); ?>
<?php endwhile; ?>
Now, the HTML in this and the layout of the theme tags you will need to edit to suit your own design. But, what it is doing is running a query to fetch a single post (the latest one) from the “feature” category. It then just runs the loop to display it. Also note that I am using the_content() to show the text of the post, and it stops wherever I use the “read more” break (which is part of the Wordpress editor). If I forgot to include that, it would show the entire post on the homepage and look like crap. If you don’t want to mess with this, you can just use the excerpt.
Showing the Latest Posts
Beneath the feature post, I show the latest posts down the left side of the homepage. I will leave it up to you to format this stuff and put it into a column layout, but this is how you show the latest posts:
<?php
query_posts("cat=-259");
while (have_posts()) : the_post();
if( $post->ID == $do_not_duplicate ) continue; update_post_caches($posts); ?>
<h3 class="h1" id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h3>
<div class="post-meta-top">
<div class="date"><span><strong><?php the_time(’F j, Y’); ?></strong></span> | <?php comments_popup_link(’0 Comments’, ‘1 Comment’, ‘% Comments’); ?></div>
</div>
<div class="clearboth"></div>
<?php the_excerpt(’<br />Read the rest of this entry »’); ?>
<?php endwhile; ?>
So, what’s going on here? First I’m running a query for all posts that are NOT in the category with the ID of 259. In my particular case, this is the Flip Tip videos category. Since I want to exclude those posts from that listing, I do so here. Then, I just run the loop again.
Now, you will also see that I have an IF statement in there which will exempt the post from displaying if the ID is $do_not_duplicate. This variable was defined with the feature post (see above) and the purpose of this is so that my daily feature post is not listed twice.
Showing The Videos
On my custom homepage, I am also listing the latest videos. Above, I exempted category #259. In this case, I want to exclusively list category 259. So, the query to start off the loop would be:
<?php query_posts("cat=259&posts_per_page=5"); ?>
The only addition here is that I am limiting the list to only the latest 5 videos.
Feel Free To Cheat
I’m not going to be able to turn you into an expert Wordpress theme hacker in this post, however hopefully I’ve given you a good start.
Remember, often you can swipe code from other files in your theme. You will see “the loop” used in multiple Wordpress files. In my custom version, I’m simply duplicating the loop and starting it off with my own criteria and customizing the appearance.
You can also download free WP themes for the only purpose of looking at the code to see how they did things. Then, just copy it to your own theme. This is how we learn.
If you enjoyed this article, you might also like...
- How To Use a Custom Page Template In Wordpress
- How I Converted a Non-Blog Site to Wordpress
- How To Replace Your Wordpress Search With Google
- Using Gravatars On Your Blog – Why And How
- Using Wordpress to Podcast and Video Blog
-
André
-
Christian
-
Marc
-
Christian
-
Wizard of Aus
-
Stuart Conover
-
Blog Expert
-
JR Griggs
-
Chris
I'm David Risley. I've been making my living as a blogger for over a decade. Blogging is my business and how I support my family. With this blog, I'm just gettin' REAL and telling you how this business works.








