Defining the Home Page
Wednesday, October 7th, 2009 by MikeLTIn the main hierarchy of things, the first page to load when someone clicks on a link to your domain would be index.php. This is the template file that we used to create the look, feel, and functionality of our theme in general, and is and should remain the template from which all subsequent templates splinter.
Having recognized that the first page to load should be as customizable as any other page, Wordpress developers have allowed the template file home.php to take precedence over index.php as the home page.
The conventional home page for a Wordpress blog consists of a number of blog posts (usually 10) in chronological order with the most recent being at the top of the page. This, however, does not have to be.
The home page of a Wordpress blog can be a single page iteself (i.e. About), an older Blog Post that is important enough to stick to the top of the list (i.e. “sticky”), a landing page for a particular category, or just about anything you want to convey at your “front door”. It can contain full posts, short exerpts that cut off at 55 words, or exerpts whose length you controll with the more tag.
What you choose to include or not to include on the home page is all determined inside the loop.
I have determined that the homepage for this site (for now anyway) will be pretty conventional, so lets go through the loop.
<!–WP-Loop for home.php–>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : (the_post()); ?>
<!– styles the title as h2 and links it to the post page –>
<h2><a href=”<?php the_permalink() ; ?>” rel=”bookmark” title=”Permanent link to <?php the_title() ; ?>”><?php the_title(); ?></a></h2>
<!– post date in small type –>
<small>Posted on <?php the_date(); ?></small>
<!– fetches the entire content of the post –>
<?php the_content(); ?>
<!– Post Meta Data –>
<p>Posted in <?php the_category(‘, ‘); ?><strong> | </strong><?php edit_post_link(‘Edit’,”,’<strong>|</strong>’); ?>
<?php comments_popup_link(‘No Comments »’, ‘1 Comment »’, ‘% Comments »’); ?></p>
<?php endwhile; ?>
<?php else : ?> <!– what to do if there are no posts –>
<h2>Not Found</h2>
<p>Sorry, but you are looking for something that isn’t here.</p>
<?php get_search_form(); ?>
<?php endif; ?>
Like I said pretty basic stuff. The home page will consist of the blog posts in chronological order. Each post will have the title linked to the actual post page, and show the date posted.
I could have chosen to show only excerpts of the post by using:
<?php the_content(‘Read More’); ?>
<?php the_excerpt(); ?>
instead of:
<?php the_content(); ?>
…but that would cut the excerpt at 55 words, so I will control the size of the excerpt using the more tag on the individual post.
Not wanting a lot of clutter, I note the category the post belongs to, add a quick link for the logged in author to edit the post, and indicate the number of comments with a link to the comments section of the actual post page. This is commonly known as the Post Meta Data section.
Standard procedure is to end with what to do if there are no posts (if) just before you end the if statement.
Tags: hierarchy, home page, template page, the loop, themes, web development, wordpress
Leave a Reply
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.



