• alxdesign

    (@alxdesign)


    I’m just wondering how I should do if I want, let’s say, 2 sidebar files. And include them on differnet pages… Is it possible? I can’t figure it out since all pages except the index uses page.php as base.

    http://www.alxdesigns.com/dev/wp2/home/

    The sidebar there… I’d like to be able to switch it depending on what page you are on.

    Also, is there any way to edit the sidebar text from admin panel? Maybe one way could be to totally remove the sidebar, and inclue the sidebar in each page, which will make it possible to edit as I want. Any suggestions?

Viewing 3 replies - 1 through 3 (of 3 total)
  • eyephoto

    (@eyephoto)

    Off the top of my head something like:

    Create:
    Sidebar1.php
    Sidebar2.php

    Then an ‘if’ statement in the page.php to call individual sidebars depending on where you are? as I’m not a coder you’ll have to find out what you need from the Codex or maybe someone can expand on this.

    Usually all the changes I do are using code already included in the theme just have to change to suit.

    Sorry couldn’t be more specific.

    Yes Im wanting to do something similar too. I want to call a seperate sidebar for category 83.

    I think it will involve using conditional tags to call seperate sidebars

    http://codex.wordpress.org/Conditional_Tags#The_Main_Page

    but like you I arent a php coder so cant shine any more light on what is required and into whccih file the code should be inserted.

    Sadly these forums are sometimes slow, so its often worth submitting your question into one of the popular php forums on the net.

    Actually the answer is in that codex page under:

    ‘Variable Sidebar Content’

    just change to suit.

    As an example for glennk:

    <?php
    // let's generate info appropriate to the page being displayed
    if (is_home()) 
    
    (Normal sidebar content here that is shown when on the 'home' page)
    
    elseif (is_category('83')) {
    // we're looking at a single category view, so show the relevant information
    echo "<ul>"; Your optional content here
    echo "</ul>";
    } ?>

    or as a pointer, I use this on my own sidebar:

    <?php if(is_home()) { ?>
    <h2>About</h2>
    Content here
    <? } ?>
    
    <?php if(is_single()) { ?>
    <h2>More information</h2>
    <?php the_meta(); ?>
    <? } ?>

    and put:

    <?php endif; ?> at the end of the sidebar before the last </div>

    This shows the ‘About’ info only on the ‘home’ page and if it’s a single page/post shows the ‘meta’ I’ve entered into the custom fields for that page/post under ‘More Information’ in the sidebar.

    The example code above I’ve shown may not be spot on but hopefully gives you more of an idea and is possible easier to maintain than the first suggestion.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to have more than 1 sidebar file & include them on different pages?’ is closed to new replies.