WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] how to use different sidebar for some pages? (12 posts)

  1. do77
    Member
    Posted 5 years ago #

    Hi,
    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')); ?>
    
    			</div>
    				<?php edit_post_link('Edit this entry.', '<p>', '</p>'); ?>
    		</div>
    		<?php endwhile; endif; ?>
    	</div>
    
    <?php include(TEMPLATEPATH."/right.php");?>
    
    <?php get_footer(); ?>

    What do I have to do so that when I navigate to http://url.com/?page_id=4, it will show not 'left.php' but 'left_2.php'

    Hope someone can help me. Thank you!
    do77

  2. msdana
    Member
    Posted 5 years ago #

    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!

  3. tluskie
    Member
    Posted 5 years ago #

    This should help too. Step by step instructions on how to set this up on your templates. http://blogcraving.com/sidebars-pages-wordpress-blog/

  4. do77
    Member
    Posted 5 years ago #

    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!
    do77

  5. iocchelli
    Member
    Posted 5 years ago #

    Ok,

    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?

  6. do77
    Member
    Posted 5 years ago #

    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?

    thanks
    do77

  7. do77
    Member
    Posted 5 years ago #

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

    <?php
    /*
    Template Name: Alternative
    */
    ?>

    to the page_alternative.php file.

    Thanks to all!
    do77

  8. iocchelli
    Member
    Posted 5 years ago #

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

  9. Ozymandeeus
    Member
    Posted 4 years ago #

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

  10. LeeEldridge
    Member
    Posted 4 years ago #

    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.

  11. joecat
    Member
    Posted 4 years ago #

    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.

  12. ryhr91
    Member
    Posted 4 years ago #

    @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. http://codex.wordpress.org/Customizing_Your_Sidebar It is located a little more then half way down the page after the heading " New way of adding sidebars"

    Hope that helps.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.