How to Create Different Sidebar and Footer Templates for Your Pages
WordPress allows you to create separate Sidebar and Footer templates for different pages of your WordPress site by using a simple include statement. When you write an include statement, you’re 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:
<?php get_sidebar(); ?>
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:
Create a new Sidebar template in a text editor, such as Notepad (Windows) or TextMate (Mac).
Save the file on your computer as sidebar-2.php.
The new Sidebar template is listed in your theme files on the Edit Themes page. You can open this page by choosing Appearance→Editor on the Dashboard.
To include the sidebar-2.php template in one of your Page templates, open the desired template on the Edit Themes page (Appearance→Editor) and then find this code:
<?php get_sidebar(); />
Replace the preceding code with this include code:
<?php get_template_part(‘sidebar’, ‘2’); ?>
With the get_template_part(); function, you can include virtually any file in 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 footer-2.php and then locate the following code in your template:
<?php get_footer(); ?>
and replace the preceding code with this code:
<?php get_template_part(‘footer, ‘2’); ?>
You can do multiple things with WordPress to extend it beyond the blog. The point of this example is to show you how to use WordPress to create a fully functional website with a CMS platform — anything from the smallest personal site to a large business site.