WordPress.org

Support

Support » Themes and Templates » How to delete sidebar from several pages

How to delete sidebar from several pages

  • I have this code that works for 1 specific page which is the Portfolio.

    <?php if ($post->ID != 20 && get_post_type() != ‘portfolio’)
    get_sidebar();?>

    I want to know how do I add extra pages to it?

    thank you 🙂

Viewing 9 replies - 1 through 9 (of 9 total)
  • esmi

    @esmi

    Forum Moderator

    You need to test for additional ids. You could use:
    if ( ( $post->ID != 20 && $post->ID != 54 ) && get_post_type() != 'portfolio')

    but that could quickly get clumsy and difficult to edit if you want to add quite a few pages. So something a little cleaner might look like:

    <?php
    $mypages = array( '20', '54', '78', '123');
    if ( in_array( $post->ID, $mypages ) && get_post_type() != 'portfolio')
    get_sidebar();?>

    it works but it gives me this error

    Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ‘)

    esmi

    @esmi

    Forum Moderator

    Which code are you using?

    I used this code

    <?php
    $mypages = array( ’20’, ’54’, ’78’, 123′);
    if ( in_array( $post->ID, $mypages ) && get_post_type() != ‘portfolio’)
    get_sidebar();?>

    I did use this code:

    if ( ( $post->ID != 20 && $post->ID != 54 ) && get_post_type() != ‘portfolio’)

    and it works fine

    thanks 🙂

    esmi

    @esmi

    Forum Moderator

    And what line is causing the error in that code? Also, you do know I made all of those page ids up? You need to replace them with the ids that you want.

    I did replace them with the code that I wanted

    as for what line is causing the error

    it is this line

    if ( in_array( $post->ID, $mypages ) && get_post_type() != ‘portfolio’)

    Thanks for the help 🙂

    esmi

    @esmi

    Forum Moderator

    Make sure that each of your page ids in the $mypages array has both opening and closing single quotes (‘).

    Nice
    will try that

    Thanks for your help 🙂

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘How to delete sidebar from several pages’ is closed to new replies.