SOLVED: Because I overlooked a basic feature I didn't realize existed. LOL. Veteran brain-lapse.
My attempt at something sort of works, and could I ask for a fresh set of eyes to see what I'm missing? Thanks.
I'm trying to create some conditional sidebars using Genesis Simple Sidebars, and modifying a code snippet from WPBeaches which was posted in 2014. What I want to do is have a few custom sidebars dedicated to a few specific category archives and their single posts.
I created a single test widget in each custom sidebar, wrote up the code to use two different categories with conditionals (using is_category for archive pages and in_category for single posts), and a fallback of the primary sidebar for all other categories. The result is that the sidebars work on those two categories (and one of them is a parent category which I want to cascade to its child categories), but on single posts in those two categories the result is the primary sidebar. The child category archives of the one parent category do not show the custom sidebar either. So it sort of works, but not as I expected.
I have a conditional of is_single, is_category, and is_tag to start the process. Here is the code.
// Custom sidebars with conditionals for post categories
add_action( 'genesis_before_sidebar_widget_area', 'themeprefix_remove_sidebar' ); // starts the ball rolling
function themeprefix_remove_sidebar() {
if ( is_single() || is_category() || is_tag() ) { // set your connditionals here
remove_action( 'genesis_sidebar', 'ss_do_sidebar' ); // removes Simple Sidebar
remove_action( 'genesis_sidebar', 'genesis_do_sidebar' ); // removes Genesis Default sidebar
add_action( 'genesis_sidebar', 'sb_add_sidebar' ); // adds alternative sidebar in function below
}
}
// Alternative Sidebar
function sb_add_sidebar() {
if( is_category('christian-faith') || in_category('christian-faith') ) {
dynamic_sidebar( 'faith-sidebar' );
}
elseif( is_category('classroom') || in_category('classroom') ) {
dynamic_sidebar( 'teaching-in-the-classroom-sidebar' );
}
else {
dynamic_sidebar( 'sidebar' );
}
}
And here are links to the two example category pages.
https://sallieborrink.com/category/christian-faith
https://sallieborrink.com/category/classroom/
Oe the first I have two identical test widgets. On the second one, I put the test widget first and my wife put a bunch of widgets in after it. The result is that the primary sidebar shows up, and then after that's done (the last widget is "our history timeline"), the custom sidebar starts with the test widget and the set she added.
So why I'm getting double widgets on one, and two different sets on the other, I do not know. Obviously there's something I don't understand here.