Site logo

Archived topic

Display different widgets for single posts

5 replies · Started by Theresa on December 9, 2020

Viewing posts 1–6 of 6

I have the single post sidebar layout set to "Content/Sidebar" in the Customizer. I want to display different content in the Sidebar area for single posts based on the post category. I'm not using the right sidebar or left sidebar widgets. I created 2 sidebars and they are visible in Appearance -> widgets. I used the register_sidebar() function to create them (using Code Snippets plugin) and added the widgets for the 2 sidebars.

The issue is I don't know how to get them to display in the sidebar area (as specified in the single post sidebar layout). Pretty sure I need to use dynamic_sidebar(). Do I need a hook? I've been unable to get this to work.

I'm coming from the Genesis framework world and this was done as follows. Not sure how to adapt for GeneratePress:
genesis_register_sidebar( array(
'id' => 'news-sidebar',
'name' => __( 'News Sidebar', 'tws' ),
'description' => __( 'This is the widget area for the News sidebar.', 'tws' ),
) );

add_action( 'genesis_before_sidebar_widget_area', 'business_pro_news_genesis');
function business_pro_news_genesis() {
if ( in_category( array('in-the-news', 'press-releases', 'events' )) )
genesis_widget_area ('news-sidebar', array(
'before' => '

',
'after' => '

',
) );
}

Theresa Thomson

Thank you so much! I had actually installed that plugin but had used it incorrectly. Got it now!

No problem :)

I had exactly the same query and that plugin works really well. Thanks for the recommendation

Glad to hear!

This archived topic is closed to new replies.