ThemeShaper Forums » Thematic

Removing sidebar on child pages

(8 posts)
  • Started 4 years ago by sunlamp
  • Latest reply from sunlamp
  • This topic is resolved
  1. sunlamp
    Member

    Hi there

    I'm finding the 'Removing the Sidebar' code snippet at the Code Bar very helpful

    http://www.wupperpiraten.de/2009/03/how-to-remove-the-sidebar-from-a-certain-page/

    However my PHP isn't up to much.

    Can anyone suggest how I can make this code work to remove the sidebars from all the child pages of a given page?

    Thanks for your help!

    david

    Posted 4 years ago #
  2. amygail
    Member

    I've not attempted this myself - but maybe there's an answer for you here

    http://codex.wordpress.org/Conditional_Tags

    scroll down to:

    "Testing for sub-Pages"

    Posted 4 years ago #
  3. sunlamp
    Member

    Hi Amy

    Thanks for your help.

    I customised the code with the Conditional Tags on the page you suggested.

    Now I've managed to remove the sidebar from the parent page, but not from any of its children. Is there something I'm doing wrong?

    // remove sidebar for certain pages
    // http://www.wupperpiraten.de/2009/03/how-to-remove-the-sidebar-from-a-certain-page/
    // filter thematic_sidebar() .. no display for the page 'Visualizations' & its children
    
    function remove_sidebar() {
    	// We test if we are on the page 'Visualization'
    	if ( is_page('Visualizations') || $post->post_parent == '5' ) {
        // the page is "Visualizations", or the parent of the page is "Visualizations"
    
    		// Yes, we are .. now we switch off the sidebar
    		return FALSE;
    	} else {
    		// we are not .. we leave the switch on
    		return TRUE;
    	}
    }
    // Connect the filter to thematic_sidebar()
    add_filter('thematic_sidebar', 'remove_sidebar');
    
    ?>
    Posted 4 years ago #
  4. Not certain how it could be used in your code, but there is the child_of parameter for wp_list_pages.

    wp_list_pages("title_li=&child_of=$id&show_date=modified

    Posted 4 years ago #
  5. I'm no php ninja myself, but this might help you... tbr_article_family
    all you need to do is install and activate this plugin and use tbr_is_decendant_of("place page id here") for testing for subpages (and grandchildren).

    so this would make:


    function remove_sidebar() {
    // We test if we are on the page 'Visualization, with an example page ID of 4'
    if ( is_page('Visualizations') || tbr_is_decendant_of(4)) {
    // the page is "Visualizations", or the parent of the page is "Visualizations"

    // Yes, we are .. now we switch off the sidebar
    return FALSE;
    } else {
    // we are not .. we leave the switch on
    return TRUE;
    }
    }
    // Connect the filter to thematic_sidebar()
    add_filter('thematic_sidebar', 'remove_sidebar');

    hope this helps :D

    Posted 4 years ago #
  6. amygail
    Member

    If you can't find an answer another option is to make a custom page template with no sidebars and use that.

    You an also hide sidebars via css - but that's kind of cluncky

    Posted 4 years ago #
  7. You can't use one of the globals without defining it.

    global $post;

    at the beginning of your function should resolve it.

    Chris
    - still one week on vacation

    Posted 4 years ago #
  8. sunlamp
    Member

    Thanks all!

    Chris's suggestion solved it.

    function remove_sidebar() {
        global $post;
    	// We test if we are on the page 'Visualizations'
    	if ( is_page('Visualizations') || $post->post_parent == '5' ) {
        // the page is "Visualizations", or the parent of the page is "Visualizations"
    
    		// Yes, we are .. now we switch off the sidebar
    		return FALSE;
    	} else {
    		// we are not .. we leave the switch on
    		return TRUE;
    	}
    }
    // Connect the filter to thematic_sidebar()
    add_filter('thematic_sidebar', 'remove_sidebar');

    And then I also used this in style.css to widen the content areas on all the child pages of parent page id=5

    body.parent-pageid-5 #container {
    	width: 960px;
    }
    
    body.parent-pageid-5 #content {
    	width: 940px;
    }

    Thanks again
    david

    Posted 4 years ago #

RSS feed for this topic

Reply

You must log in to post.