• I use dynamic sidebars to give different pages their own sidebars. The problem is that the subpages get the default sidebar instead of the same sidebar as the parent page.

    What can I add to this:

    if ( is_page('pagename') ) { dynamic_sidebar( 'sidebar_pagename' );

    to make sure that a subpage gets the same sidebar as the parent page?

Viewing 1 replies (of 1 total)
  • Not had time to test this but something like the following:

    <?php
    
    /* check whether this is a child page */
    if( $post->post_parent > 0 ) {
    
    	/* get the post parent id */
    	$mdw_post_parent_id = $post->post_parent;
    
    	/* get the post parent slug */
    	$mdw_slug = basename( get_permalink( $mdw_post_parent_id ) );
    
    /* not a child page - has no parent id */
    } else {
    
    	/* get the post slug */
    	$mdw_post_slug = basename( get_permalink( $post->ID ) );
    
    }
    
    /* load dyamic sidebar using slug */
    dynamic_sidebar( 'sidebar_' . $mdw_post_slug );
    
    ?>
Viewing 1 replies (of 1 total)
  • The topic ‘Dynamic sidebars for subpages’ is closed to new replies.