Forums

[resolved] Custom Sidebars on Custom Pages in WP 2.7 (4 posts)

  1. PghDave
    Member
    Posted 3 years ago #

    Hello all;

    I am attempting to do what one would probably consider relatively easy at this point, but for some reason I have been at wits end to get it to work properly.

    For reference, I am trying to modify http://firefoxnewsonline.com .

    Essentially, what I want is for certain pages to display custom sidebars. In previous versions of wp, I could modify the specific page as it appeared in the editor list. In version 2.7 however, it seems 'pages' have been replaced into 'posts' of their own, and it seem I must add "if/else" commands in the page.php template.

    As an example,
    - when George's 'About' page is selected, I want "sidebar-george.php" called;
    - when Dave's 'About' page is selected, I want "sidebar-dave.php" called.

    That said, if George's page is "../wp-admin/page.php?action=edit&post=5" &
    Dave's page is "../wp-admin/page.php?action=edit&post=6" ,
    what would the code look like?

    (This is what I have in the page.php)

    <?php get_sidebar(); ?>
    
    <?php
    if (is_page('5')) {
     include(TEMPLATEPATH . '/sidebar-george.php');
    elseif ( is_page('6')) {
    include(TEMPLATEPATH . '/sidebar-dave.php');
    } else {
    include(TEMPLATEPATH . '/sidebar.php');
     }
     ?>
    
    <?php get_footer(); ?>
  2. darya8
    Member
    Posted 3 years ago #

    I use a plugin called Widget Logic. You can use functions like is_page() or is_category(). You can put things in the parenthesis to make it even more specific. Call a custom sidebar widget to more pages by using || e.g. `is_page('About') || is_page('Contact')
    `
    This is one of my favorite plugins :)

  3. PghDave
    Member
    Posted 3 years ago #

    Darya8;

    Thanks for the response, and yes, I could see where that would be useful if there were certain widgets I want on certain pages but not others. However, the problem is I cannot get those certain pages to bring up their appropriate sidebar.

    In this case I want sidebar-dave.php to come up when we click on Dave's page, and sidebar-george.php to appear when we click on George's page. Once they they are called up properly, I believe Widget Logic will be a perfect complement to adjusting such.

    I am assuming I either editing the wrong php document, and the script I posted above has some inaccuracies (or both). Any guidance would be greatly appreciated.

    Thanks all & respects,
    Dave

  4. PghDave
    Member
    Posted 3 years ago #

    Disregard, figured it out.
    The problem was that the script was "copy & paste"ed, & was missing a "}". Should have read:

    <?php get_sidebar(); ?> <--this needed to be removed

    <?php
    if (is_page('5')) {
    include(TEMPLATEPATH . '/sidebar-george.php');
    } <--this was where it was missing
    elseif ( is_page('6')) {
    include(TEMPLATEPATH . '/sidebar-dave.php');
    } else {
    include(TEMPLATEPATH . '/sidebar.php');
    }
    ?>

    <?php get_footer(); ?>

Topic Closed

This topic has been closed to new replies.

About this Topic