ThemeShaper Forums » Thematic

[closed]

How to implement this using my child theme

(2 posts)
  • Started 3 years ago by mrmikeman
  • Latest reply from middlesister
  • This topic is not resolved
  1. mrmikeman
    Member

    I found an article to help me with displaying a different sidebar on each Post.

    http://www.wpbeginner.com/wp-themes/display-different-sidebar-for-each-post-and-page-for-wordpress/

    And I dont know how to implement this using a child theme, from what I think I have to filter this sense its a child theme, could someone tell me how to implement this in thematic?

    Posted 3 years ago #
  2. middlesister
    Member

    Hm, this is a tricky one. I think your best bet would be to remove the call for the standard sidebars and add the code for calling the different sidebars to thematic_belowcontainer. And since the sidebars are called outside the loop, the code needs to be a little different.
    Put this in your functions.php

    // remove the call for the sidebar
    function childtheme_remove_thematic_sidebars($show) {
    	$show = false;
    	return $show;
    }
    add_filter('thematic_sidebar', 'childtheme_remove_thematic_sidebars' );
    
    // and add a call for your custom sidebars
    function childtheme_add_custom_sidebars() {
    	global $wp_query;
    	$postid = $wp_query->post->ID;
    	$sidebar = get_post_meta($postid, "sidebar", true);
    	get_sidebar($sidebar);
    	wp_reset_query();
    }
    add_action('thematic_belowcontainer', 'childtheme_add_custom_sidebars');

    Then you need to have files in your childtheme that corresponds to the different sidebars you want. If you want to take advantage of thematics widget areas, you could use one sidebar for the primary widget area and one sidebar for the secondary. Create two files in your childtheme folder named sidebar-primary.php and sidebar-secondary.php. Then in each of these files you make the call for the widget-area you want.

    sidebar-primary.php

    <?php 
    
        // action hook for placing content above the main asides
        thematic_abovemainasides();
    
        // action hook creating the primary aside
        widget_area_primary_aside();	
    
        // action hook for placing content below the main asides
        thematic_belowmainasides(); 
    
    ?>

    sidebar-secondary.php

    <?php 
    
        // action hook for placing content above the main asides
        thematic_abovemainasides();
    
        // action hook creating the primary aside
        widget_area_secondary_aside();	
    
        // action hook for placing content below the main asides
        thematic_belowmainasides(); 
    
    ?>

    Of course you can put whatever you want in these files, this is just a suggestion.
    Then, in order to use the sidebars you have to remember to specify a custom field with the name "sidebar" and value of either "primary" or "secondary" on each post or page. I haven't tested this myself, but I think it should work.

    Posted 3 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.