Creating a Static Home Page


A default WordPress install puts a list of recent posts derived from wp-content/themes/default/index.php on the home page of your blog. You may prefer the home page to have more static content, perhaps with links to your blog and to other sections of your site.

This is easy to achieve. One method is to use a plugin, such as the Static front page plugin discussed in Chapter 7. Another method is to make use of the way WordPress uses template files.

When a visitor calls up your Website WordPress first looks in the theme folder for a template file called home.php. If it fails to find that file, it next looks in the theme folder for a template file called index.php. Since the default theme does include index.php but not home.php WordPress uses index.php to display your blog.

To create a static home page all you have to do is create a file called home.php, containing whatever WordPress template tags, text, images, and links you wish to use, and add it to the theme folder.

Tips

  • This technique applies only to WordPress installed on your own server and not to WordPress.com blogs.

  • There is more information on the template hierarchy at: codex.wordpress.org/Template_Hierarchy.


To create a static home page

1.

Use your text editor to create a new blank document that will become the home page for your site.

2.

To give your page the same header, stylesheet, sidebar and footer as the rest of your WordPress site add these three lines of code:

<?php get_header(); ?> <?php get_sidebar(); ?> <?php get_footer(); ?>


3.

Save the file with the file name home.php. If you include only the code above, your Home Page will display the header, sidebar and footer, but no other content.

4.

Add your own content after the line that reads: <?php get_header(); ?> (Figure 1).

Figure 1. I've created a very simply home.php file in my text editor.


5.

Upload home.php to your blog's theme folder. It instantly supersedes index.php as the Home Page (Figures 2 and 3).

Figures 2 & 3. Before and after: The standard home page based on index.php shows my one recent post (top). After adding home.php to the theme folder the front page shows my customized content: a few links to the various sections of my site, framed with the usual header, sidebar and footer (bottom).


Tips

  • In the Default theme the content of a page is normally wrapped inside a div with the id of content and a class of narrowcolumn: <div >your content here</div>. Ensure your new content has appropriate styling.

  • If you wish to include posts on this static Home Page you need to include the coding for The Loop. Chapter 6 has detailed information about how a theme is put together, including the function of The Loop.





WordPress 2. Visual QuickStart Guide
WordPress 2
ISBN: 0321450191
EAN: 2147483647
Year: 2004
Pages: 142

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net