0

I'm using the Divi theme to build my website.My client wants News and Blog page on the same site, so I did this by using categories.

My problem is how to achieve category(i.e News and Blog) specific sidebars? By default, posts uses the default sidebars. I set the default sidebar to my Blog page.

I've installed the widget logic plugin also. Please help me to solve this scenario with the plugin.

1

Create a child theme (if you haven't already) and register two sidebars:

function wpse_151695_register_sidebars() {
    register_sidebar(
        array(
            'name' => 'News',
            'id'   => 'sidebar-news',
        )
    );

    register_sidebar(
        array(
            'name' => 'Blog',
            'id'   => 'sidebar-blog',
        )
    );
}

add_action( 'widgets_init', 'wpse_151695_register_sidebars' );

Then in your sidebar.php:

if ( is_singular() ) {
    // For single posts, show the sidebar relevant to the category it's assigned to.
    if ( has_category( 'news' ) )
        dynamic_sidebar( 'news' );
    elseif ( has_category( 'blog' ) )
        dynamic_sidebar( 'blog' );
} elseif ( is_category() ) {
    if ( is_category( 'news' ) )
        dynamic_sidebar( 'news' );
    elseif ( is_category( 'blog' ) )
        dynamic_sidebar( 'blog' );  
}
0

If you don't want to get into PHP coding in your functions.php file of the child theme you could try adding the Custom Sidebars plugin from WPMUDEV. It will give you the ability to generate any number of specific sidebars and then specify on a page or post basis which sidebar to display with that content. Widgets are added in the Appearance/Widgets dashboard as with any sidebar.

It probably would be a good idea to then remove the Display Widgets plugin as the two plugins may work against each other or could just make things more complicated.

The Display Widgets plugin, as I understand, allows the display or hiding of widgets in existing sidebars, while the Custom Sidebars plugin allows generating any number of sidebars and displaying them on specific pages/post while using any widgets that you place in the sidebars.

Hope that helps.

  • Thanks for the reply now the news page and blog page of my website has sidebars to specific to those, but now the new problem raised on the widgets side. Specifically Calendar and Archive widget are mixing. news posted and blog posted dates are getting mixed up.Please suggest me how to filter these based on category. Please help me with the plugin if possible. – user3773610 Jul 11 '14 at 6:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.