• I have found two code snippets for excluding an element (in this case, the sidebar). Can anyone tell me what the difference is between them? The first one is always the one recommended, but the second one seems to do exactly the same thing.

    <?php if (is_page('1'))
    {}
    else {
    get_sidebar();
    }
    ?>
    <?php if (!is_page('1')) { ?>
    <?php get_sidebar(); ?>
    <?php } ?>
Viewing 3 replies - 1 through 3 (of 3 total)
  • Both exclude the sidebar if the page ID is one, however the first has a set of braces where you could do something else!

    Example switch the sidebar (version 3 with a template part)

    <?php if (is_page('1')) {
       /* get new sidebar in template part /*
       get_template_part( 'sidebar', 2 );
    } else {
       /* get the normal sidebar one */
       get_sidebar();
    }?>

    This one will leave a space where the sidebar should be on page ID one!

    <?php if (!is_page('1')) { ?>
       <?php get_sidebar(); ?>
    <?php } ?>

    HTH

    David

    Thread Starter Seijun

    (@seijun)

    So basically one just deletes the sidebar and the other also deletes the sidebar but also gives the option to replace it with something else..

    Not delete,just not load it!

    So basically both will not load the sidebar if the page ID is 1 and the the first code block is an ‘if then else endif’ statement where you can load something ‘else’ only if the page ID is 1 ..

    David

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Difference between these two exclusion conditionals?’ is closed to new replies.