Cleaning Out the Template

The first step in creating this sort of custom home page is to find the template you
want and prepare it for editing. In virtually all modern themes, the index.php template
is the one you want. It creates a home page with the standard list of posts. (The
only exception is if your theme has a home.php file—if it does, edit that template
instead.) To get started, choose Appearance→Editor and then pick “Main Index
Template (index.php).”
In many ways, the index.php template is like the category.php template you considered
in the first part of this chapter. The heart of both is a loop that extracts and
displays posts. The most significant difference is that category.php uses a narrower
query that includes the posts in just a single category.
You could keep the standard loop in the index.php template and simply change the
way it displays each post. You’ve seen examples that use this technique to highlight
new posts  and change the post order. But here makes
a more radical change—it grabs several separate post lists, by category, and then
displays them. The easiest way to make this happen is to remove the existing loop
entirely and add all new code. In most themes, that means deleting everything
inside the content <div>.
In the PinBlack theme, deleting the loop leaves you with this exceedingly simple
skeleton:

<?php get_header(); ?>
<div id=”content” class=”clearfix”>
</div> <!– end #content –>
<?php get_footer(); ?>

All this template does is add a header and footer to a page. In between is a great
big empty section where you can slot in your own content.

NOTE Remember, the header template (header.php) isn’t just a header—it has the HTML markup that begins
each page, which includes the title, style sheet links, background, and menu. Similarly, the footer template (footer.
php) includes the HTML that ends every page. So even in a simple stripped-down template like the one shown
above, your site ends up with a fully formatted home page, albeit one that doesn’t have any content in it.

Advertisements
Cleaning Out the Template

Changing Your Home Page

If the list of posts is less important on your site, or if you
want to show some sort of welcome message, or if you just want to direct traffic (in
other words, give readers the option of reading posts or going elsewhere on your
site), it makes sense to start by showing a page instead of a post.

Creating a Brochure Site

The simplest way to change your home page is to ditch the post system altogether,
using pages instead of posts throughout your site. The resulting all-pages site is
sometimes called a brochure site, because it resembles the sort of informational
pamphlet you might pick up in a store.

Should You Build a Brochure Site?
A brochure site may make sense if you’re building a small site
with very simple content. The restaurant site in Figure 7-17 is
one example.
But if you’re trying to decide between a brochure site and a
post-based site, consider two questions. First, would your site
be more attractive to readers if you included posts? Even the
bare-bones restaurant site might be more interesting with
posts that chronicle restaurant news, menu experiments,
and special events. Not only that, but the fact that posts are
frequent, dated, and personal makes the site more vibrant. In
addition, if you want to get people talking on your site—for
example, posting comments about recent meals or sending in
requests and off-the-wall recipe ideas—you’ll have more luck
if you include posts. Think of it this way: A brochure site feels
like a statement, while a blog feels like a constantly unfolding
conversation.
Then again, you may decide that a brochure site is exactly
what you want. Maybe you really don’t have time to spend
updating and maintaining a site, so you simply want a place
to publish some basic information on the Web and leave it at
that. You can still take advantage of several of WordPress’s
best features, like themes, which ensure that your pages look
consistent. You’ll also get WordPress’s help if you want to track
visitors (page 444), add sharing buttons (page 412), or add any
one of a number of features described in this book.

TIP If you use a custom page for your home page, you may want to jazz it up with a few more navigational
features. Many themes provide page templates that can help you out by adding a widget-stocked sidebar beside
your page content,

Creating a Custom Entry Page

Even if you want to change your home page, you might not want to ditch the post
system. In such a case, use a static home page (called a welcome page), and include
a full complement of posts on another page.
The trick to doing this is specifying a URL for the page that displays your posts.
Here’s where things get slightly bizarre. To get the URL for your posts, you create
yet another page. This page is just a placeholder—its sole purpose is to provide the
web address for the posts page. You don’t actually need to put any content on this
page, because WordPress automatically creates the list of posts.

NOTE If you use the self-hosted version of WordPress, you need to make sure you changed your site’s
permalink setting to use post titles rather than post IDs (page 117). Otherwise, the link to your placeholder page
will use the post’s ID, not its name. This is terribly confusing—it means you’ll end up with a permalink with a
name like http://magicteahouse.net/?p=583 that actually shows your list of posts.

Even though you created a posts page, that doesn’t mean your visitors know
about it. They need a way to get there, and the best option is a link in your site’s
menu. Creating that is easy—you simply add a new menu item that points to
your placeholder page.

In some cases, you may decide not to lump all your posts together in a single reverse chronological
stream. In that case, you don’t need to create the placeholder page.
Instead, you can add category links to your menu so that visitors browse all the
posts that fall into a particular category.
This is a great approach, but it may become less practical if you have a lot of categories,
because you don’t want to burden your site with a crowded, clumsy menu.
One solution—provided you have a self-hosted site—is to customize your home page
with the theme-editing tricks

Changing Your Home Page

Using Excerpts on Your Home Page

At this point, you might think that it’s not worth the trouble to write excerpts for
all your posts. And you could be right, if you use a standard theme and you don’t
think that your visitors are going to be searching for posts. However, there’s another
factor to consider: Some themes use excerpts for other purposes.
For example, many themes use excerpts as the display text for posts on the home
page. This way, the excerpt acts a bit like a teaser. The difference is that the standard
WordPress teaser comes from the first part of a post, but you control the wording
in an excerpt.
The Brightpage theme described earlier (page 192) uses this system. If you provide
an excerpt for a post, that’s what shows up on your home page, not the post content.
The Oxygen theme, available for both WordPress.com and self-hosted sites, does
the same thing, as you can see in Figure 6-21.

NOTE None of the year themes like Twenty Twelve make much use of the excerpts feature. They use them
in searches (as shown in Figure 6-20), but not on the home page.
If you switch to a theme that makes heavy use of excerpts, you might find the summary
so valuable that you want all your posts to use them, even the ones you’ve
already created. WordPress has some plug-ins that can help. For example, the Excerpt
Editor (http://tinyurl.com/csudedx) can give you a summary for every existing post,
without you having to edit each one individually.

Using Excerpts on Your Home Page