Creating Different Page Views Using WordPress Templates

As we explain in Book IV, Chapter 2, a static page contains content that doesn't appear on the blog page, but as a separate page within your site. You can have numerous static pages on your site, and each page can have a different design, based on the template you create. (Flip to Book VI to find out all about choosing and using templates on your site.) You can create several static-page templates and assign them to specific pages within your site by adding code to the top of the static-page templates.

Here's the code that appears at the top of the static-page template Lisa uses for her About Us and Our Blog Designers page at www.ewebscapes.com/about:

<?php
/*
Template Name: About Page
*/
?>

Using a template on a static page is a two-step process: Upload the template, and then tell WordPress to use the template by tweaking the page's code.

image In Book VI, you can discover information about Custom Menus, including how to create different navigation menus for your Web site. You can create a menu of links that includes all the pages you created in your WordPress Dashboard. You can display that menu on your Web site by using the Custom Menus feature.

Uploading the template

To use a page template, you have to create one. You can create this file in a text-editor program, such as Notepad. (To see how to create a template, flip over to Book VI, which gives you extensive information on WordPress templates and themes.) To create an About page, for example, you can save the template with the name about.php.

When you have your template created, follow these steps to make it part of WordPress:

  1. Upload the template file to your WordPress theme folder.

    You can find that folder on your Web server in /wp-content/themes. (See Book II, Chapter 2 for more information about FTP.)

  2. Log in to your WordPress Dashboard and click Editor in the Appearance drop-down list.

    The Edit Themes page opens.

  3. Click the about.php template link located on the right side of the page.
  4. Type the Template Name tag directly above the get_header() template tag.

    The header tag looks like this: <?php get_header(); ?>.

    If you're creating an About Page, the code to create the Template Name looks like this:

    <?php
    /*
    Template Name: About Page
    /*
    ?>
  5. Click the Update File button.

    The file is saved, and the page refreshes. If you created an About Page template, the about.php template is now called About Page in the template list on the right side of the page.

Figure 6-1 shows the Page template and displays the code needed to define a specific name for the template.

Figure 6-1: Naming a static-page template.

image

Assigning the template to a static page

After you create the template and name it the way you want it, assign that template to a page by following these steps:

  1. Click Add New in the Pages drop-down list.

    The Add New Page page opens, where you can write a new post to your WordPress blog.

  2. Type the title in the Title text box and the page content in the large text box.
  3. Select the page template from the Page Template drop-down list.

    By default, the Page Template drop-down list in the Attributes module appears on the right side of the page. You can reposition the modules on this page; see Book III, Chapter 2 for more information.

  4. Click the Publish button to save and publish the page to your site.

Figure 6-2 shows the layout of Lisa's home page on her business site at www.ewebscapes.com and the information it contains, whereas Figure 6-3 shows the layout and information provided on the Services page at www.ewebscapes.com/services. Both pages are on the same site, in the same WordPress installation, with different static-page templates to provide different looks, layouts, and sets of information.

Figure 6-2: Lisa's home page at E.Web scapes.

image

image A lot of the content in this chapter dips into working with WordPress templates and themes, a concept that gets introduced, in depth, in Book VI. If you find the topics in this chapter intimidating at all, then work through Book VI before returning to this chapter to go through each of the methods for creating page and category templates so that you can enhance your blog.

Figure 6-3: The Services page at E.Web-scapes.

image

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.157.39