Support » Fixing WordPress » if/else problem

  • I just figured out how to create a different sidebar for individual pages using the if/else tag. While it works if I use the tag for one page I can’t figure out how to set multiple if/else tags. For example I ahve a seperate sidear for each of the pages I have. My current coding looks like this:

    <?php if ( is_page(‘Biography’) ) { ?>
    <?php include (‘sidebar1.php’); ?>

    <?php } else { ?>
    <?php get_sidebar(); ?>
    <?php } ?>

    <?php if ( is_page(‘8, 9, 11, 12’) ) { ?>
    <?php include (‘sidebar2.php’); ?>

    <?php } else { ?>
    <?php get_sidebar(); ?>

    <?php } ?>

    <?php if ( is_page(‘Linkage’) ) { ?>
    <?php include (‘sidebar3.php’); ?>

    <?php } else { ?>
    <?php get_sidebar(); ?>

    <?php } ?>

    <?php if ( is_page(’17, 18′) ) { ?>
    <?php include (‘sidebar4.php’); ?>
    <?php } else { ?>
    <?php get_sidebar(); ?>

    <?php } ?>

    Obviously this si incorrect as the pages either show the default sidebar or the deafulat sidebar and an eeror parse message. How am I supposed ot code this? Do I only list one else tag or is there another way to code it. This might be confusing so just ask for me to explain agai if needed 😉

Viewing 5 replies - 1 through 5 (of 5 total)
  • This isn’t exactly built on the example I have showed you 🙂
    Again, I am not a coder, but I am good in copy/paste “technique”! So, Id’d try something like

    <?php
    if ( is_page('3') ) {
    include(TEMPLATEPATH . '/sidebar3.php');
    } elseif ( is_page('4') ) {
    include(TEMPLATEPATH . '/sidebar4.php');
    } elseif ( is_page('5') ) {
    include(TEMPLATEPATH . '/sidebar5.php');
    } else {
    include(TEMPLATEPATH . '/sidebar.php');
    }
    ?>

    I am not sure the TEMPLATEPATH is needed, but it never hurts 🙂

    Thread Starter ericalmighty

    (@ericalmighty)

    oh…right I should have known lol. thanks once again moshu 😉

    Thread Starter ericalmighty

    (@ericalmighty)

    Awww dang…I tried the code you posted but it doesn’t work :(. The Bio page is showing the right sidebar but the other pages are showing blank. Now what?

    Thread Starter ericalmighty

    (@ericalmighty)

    um….nevermind. I got it working. Just edited the code slightly 😀

    After you reported it didn’t work, I tested on my local install and it worked perfectly as I wrote it up here. Just changed the ID#s to fit my Pages.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘if/else problem’ is closed to new replies.