• Hi,

    On my website, I have a sidebar on all pages, I only want it to be displayed on the parent of Office Interiors and children:
    here is my website: here
    here is my code:

    [Code moderated as per the Forum Rules. The maximum number of lines of code that you can post in these forums is ten lines. Please use the pastebin]

Viewing 7 replies - 1 through 7 (of 7 total)
  • if( is_page(  'services' ) ){
       get_sidebar( );
    }
    Thread Starter jbiddulph

    (@jbiddulph)

    great thanks… and what if that page has child pages?

    this is just for the parent; you can add more pages by doing this:

    if( is_page(  'serivces'  ) || is_page(  'other-page'  ) || is_page(  'even-another'  ){
    
       }

    Use the page slug instead of ‘other-page’ and separate each is_page() request with two pipesigns ( || )

    Thread Starter jbiddulph

    (@jbiddulph)

    ok, and how would i do this dynamically? if a new child page was added and I didn’t want to go in and add a new part o the code.

    global $post;
    if( $post->parent_id != '0' ){
      get_sidebar( );
    }

    This will display the sidebar only to childpages.

    Thread Starter jbiddulph

    (@jbiddulph)

    so what about my parent page?

    I have tried this but it doesn’t work:

    <?php global $post;
    					if( $post->parent_id != '0' || is_page(  'office-interiors'  )){
    					get_sidebar( );
    					}?>
    Thread Starter jbiddulph

    (@jbiddulph)

    Solved this now

    <?php global $post;
    					if( $post->post_parent == '0' || is_page(  'office-interiors'  )){
    					get_sidebar( );
    					}?>

    thanks for your help!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘dynamic side bar – only show on certain pages?’ is closed to new replies.