WordPress For Dummies
Book image
Explore Book Buy On Amazon

You can create separate sidebar templates for different pages of your site by using a simple include statement. When you write an include statement, you’re simply telling WordPress that you want it to include a specific file on a specific page.

The code that pulls the usual Sidebar template (sidebar.php) into all the other templates, such as the Main Index template (index.php), looks like this:

What if you create a page and want to use a sidebar that has different information from what you have in the Sidebar template (sidebar.php)? Follow these steps:

  1. Create a new sidebar template in a text editor such as Notepad.

  2. Save the file as sidebar2.php.

    In Notepad, choose File, Save. When you’re asked to name the file, type sidebar2.php and then click Save.

  3. Upload sidebar2.php to your themes folder on your Web server.

    The template is now listed in your theme files on the Edit Themes page (log in to your WordPress Dashboard, click the Editor link on the Appearance menu).

  4. To include the sidebar2.php template in one of your page templates, find this code:

  5. Replace it with this include code:

Using that include (TEMPLATEPATH statement, you can include virtually any file in any of your WordPress templates. You can use this method to create footer templates for pages on your site, for example. To do this, first create a new template with the filename footer2.php. Then locate the following code in your template:

and replace it with this code:

About This Article

This article can be found in the category: