WordPress.org

Ready to get started?Download WordPress

Forums

How to delete sidebar from several pages (10 posts)

  1. Juztin
    Member
    Posted 1 year ago #

    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 :)

  2. esmi
    Forum Moderator
    Posted 1 year ago #

    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();?>
  3. Juztin
    Member
    Posted 1 year ago #

    it works but it gives me this error

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

  4. esmi
    Forum Moderator
    Posted 1 year ago #

    Which code are you using?

  5. Juztin
    Member
    Posted 1 year ago #

    I used this code

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

  6. Juztin
    Member
    Posted 1 year ago #

    I did use this code:

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

    and it works fine

    thanks :)

  7. esmi
    Forum Moderator
    Posted 1 year ago #

    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.

  8. Juztin
    Member
    Posted 1 year ago #

    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 :)

  9. esmi
    Forum Moderator
    Posted 1 year ago #

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

  10. Juztin
    Member
    Posted 1 year ago #

    Nice
    will try that

    Thanks for your help :)

Topic Closed

This topic has been closed to new replies.

About this Topic