Dont forget about your 404 page

Error 404 pages are where servers direct browsers when a URL seeks a missing page. While it's easy to think you won't really need a 404 page with a WordPress install, you'd be surprised. Even though all the links to the article or page you deleted are removed automatically from within your site, someone else might have created a link on their site to your post, which will no longer work. The 4 04.php template page is how you'll handle these requests.

Why Linux Is Hackproof

Making the Switch

Making the Switch

Features (2) Office Productivity (1) On The Web (1)

Past Issues

January 2008 September 2007 August 2007

You might have noticed that the PHP code we use for the home.php and index. php page loops have a "catch-all fix" in case posts are not found, which will display a nice message and the search.php template page. The 4 04.php template page in the default WordPress theme does not do this (and it's also not set up to display our other template files and CSS).

Because the 4 04.php page does not require the comments or author information to be displayed, the template page that is closest to it is our page.php file. However, we want to give people additional options to get back into our content, so we'll want to place the #sidebarLT div back into it.

Creating a custom 404 template file

In order to create a custom 404 template file, follow these steps:

1. Copy the contents of your page.php template file into a new template file named 4 04.php template file.

2. You can remove the entire loop from the file.

3. Place in some encouraging text and the PHP code to include the search.php template file:

<h2 class="center">Not Found</h2>

<p class="center">Sorry, but you are looking for something that isn't here.</p>

<?php include (TEMPLATEPATH . "/searchform.php"); ?>

4. Add the #sidebarLT XHTML div and PHP WordPress template tag back in under the content div:

<div id='sidebarLT"> <?php get_sidebar();?> </div><!--//sidebarLT -->

These steps should give you a 404 error page that looks like this:

Cash For Blogging

Cash For Blogging

There are sites that will pay you upfront, pay you a percentage of the revenue that your content makes, and sites that will hire you to write or blog for them. You can start earning money per article or blog post in as little as a few days with some of these sites.

Get My Free Ebook

Post a comment