How to Create Sidebar Templates on Your WordPress Website - dummies

How to Create Sidebar Templates on Your WordPress Website

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

The sidebar is usually found on the left or right side of the main content area of your WordPress theme. It is a good place to put useful information about your site, such as a site summary, advertisements, or testamonials.

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(); ?>

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. In Notepad, choose File and then click Save. When you’re asked to name the file, type sidebar2.php, and then click Save.

  3. Use your FTP server to upload sidebar2.php to your Themes folder on your web server.

    The template is now in your list of theme files on the Edit Themes page. (To see it, log in to your WordPress Dashboard and click Editor in the Appearance drop-down list).

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

    <?php get_sidebar(); /> 

    with the code

    <?php get_template_part(‘sidebar2’); ?> 

    (which calls in a template you’ve created within your theme).

By using that get_template_part function, 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. First, create a new template that has the filename footer2.php. Then locate the following code in your template:

<?php get_footer(); ?>

and replace it with this code:

<?php get_template_part(‘footer2’); ?>

You can do multiple things with WordPress to extend it beyond the blog. With the correct knowledge you can use the default Twenty Ten theme to use WordPress to create a fully functional website — anything from the smallest personal site to a large business site.