Title: if/else problem
Last modified: August 18, 2016

---

# if/else problem

 *  [ericalmighty](https://wordpress.org/support/users/ericalmighty/)
 * (@ericalmighty)
 * [20 years, 10 months ago](https://wordpress.org/support/topic/ifelse-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)

 *  [moshu](https://wordpress.org/support/users/moshu/)
 * (@moshu)
 * [20 years, 10 months ago](https://wordpress.org/support/topic/ifelse-problem/#post-214467)
 * 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](https://wordpress.org/support/users/ericalmighty/)
 * (@ericalmighty)
 * [20 years, 10 months ago](https://wordpress.org/support/topic/ifelse-problem/#post-214468)
 * oh…right I should have known lol. thanks once again moshu 😉
 *  Thread Starter [ericalmighty](https://wordpress.org/support/users/ericalmighty/)
 * (@ericalmighty)
 * [20 years, 10 months ago](https://wordpress.org/support/topic/ifelse-problem/#post-214471)
 * 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](https://wordpress.org/support/users/ericalmighty/)
 * (@ericalmighty)
 * [20 years, 10 months ago](https://wordpress.org/support/topic/ifelse-problem/#post-214473)
 * um….nevermind. I got it working. Just edited the code slightly 😀
 *  [moshu](https://wordpress.org/support/users/moshu/)
 * (@moshu)
 * [20 years, 10 months ago](https://wordpress.org/support/topic/ifelse-problem/#post-214474)
 * 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.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 5 replies
 * 2 participants
 * Last reply from: [moshu](https://wordpress.org/support/users/moshu/)
 * Last activity: [20 years, 10 months ago](https://wordpress.org/support/topic/ifelse-problem/#post-214474)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
