Support » Fixing WordPress » how to use different sidebar for some pages?

  • Resolved do77


    I would like to use different sidebars for different pages. Right now my page template looks like this: (left.php is my sidebar)

    <?php get_header(); ?>
    <?php include(TEMPLATEPATH."/left.php");?>
    	<div id="content">
    		<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    		<div class="post" id="post-<?php the_ID(); ?>">
    		<h2><?php the_title(); ?></h2>
    			<div class="entry">
    				<?php the_content('<p class="serif">Read the rest of this page &raquo;</p>'); ?>
    				<?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
    				<?php edit_post_link('Edit this entry.', '<p>', '</p>'); ?>
    		<?php endwhile; endif; ?>
    <?php include(TEMPLATEPATH."/right.php");?>
    <?php get_footer(); ?>

    What do I have to do so that when I navigate to, it will show not ‘left.php’ but ‘left_2.php’

    Hope someone can help me. Thank you!

Viewing 11 replies - 1 through 11 (of 11 total)
  • I use the plugin Custom Widgets. You can select where you want widgets to appear. And you don’t need to fool with your theme’s code.

    Hope that helps!

    This should help too. Step by step instructions on how to set this up on your templates.

    Thanks to both of you!
    Unfortunately that doesn’t solve my problem exactly. The thing is that I need to use, lets say sidebar1.php on one page and sidebar2.php at another site. So just modifying the page.php file wouldn’t work.

    Any ideas so that different PAGES have different sidebars?

    Thank you!


    You would have page.php with sidebar1.php in it. Then, you make page-alternate.php (or another name of your choice) that includes sidebar2.php.

    NOW, when you create a new page in WordPress, the default template will be page.php. but you can select page-alternate.php from right within the editing area for the page.

    You select your template in that ‘attributes’ section below the publish button in the right side of the page editing window.

    You can do this on a page by page basis. Does that make sense?

    Hi iocchelli,

    that totally makes sense and that is exactely the way I have already tried it. But when I upload, lets say page_alt.php, it doese not show up within the attributes. i can still only choose between default template and archive.

    Any idea why it doesn’t show up?


    Ok, I just figured it out! I forgot to add

    Template Name: Alternative

    to the page_alternative.php file.

    Thanks to all!

    You beat me to it. I was just about to post that exact code. 🙂 Good going!

    thank you so much, this helped me, iocchelli this is EXACTLY the problem i had, thank you very much!

    Hey guys.

    I’m trying to achieve this same thing. And I think I’m missing a step.

    I created an alternative page and named it page-static.php

    I created an alternative sidebar called sidebar2.php

    Made two edits to page-static.php
    Added template name
    Renamed get_sidebar to get_sidebar2

    When I select this template, I don’t have a side bar and get this error where the sidebar should be:

    Fatal error: Call to undefined function get_sidebar2() in /home/snapprom/snap/html/wp-content/themes/abink-minimal/page-static.php on line 25

    So I assume I have to define a function? Where and how?

    I really appreciate this. I’m not a programmer. Know just enough to poke around and edit some things.

    I have a question and hopefully an answer to LeeEldridge’s question.
    (Though I see the post is over 1 month old – I hope it is solved already.)

    Made two edits to page-static.php
    Added template name
    Renamed get_sidebar to get_sidebar2

    Just changing the function call from get_sidebar to get_sidebar2 is not enough. You get the error because the function get_sidebar2 does not exist – you’ll need to create the function. An easier way is to rename your second sidebar template to sidebar-2.php and then use <?php get_sidebar(’2’); ?>. (This makes use of WordPress’s template naming conventions.)

    My Question:
    Do you also need to register the new widget areas in function.php?
    I did everything above, but a different widget area does not show up in my wp-admin page.

    @joecat – From what I see it looks like you only need to register the sidebar if you want to have it widget ready. If you code all the functions you want added to the particular sidebar and don’t need widgets added then it is not necessary. More info on this is in the post of the codex. It is located a little more then half way down the page after the heading ” New way of adding sidebars”

    Hope that helps.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘how to use different sidebar for some pages?’ is closed to new replies.