Help creating widgets for each category
I came across a post by athora, which was posted in 2013. Help creating widgets for each category.
Code originally from
http://bavotasan.com/2012/create-wid...-in-wordpress/
I pasted the code below into functions.php
add_action( 'widgets_init', 'category_sidebars' );
/**
* Create widgetized sidebars for each category
*
* This function is attached to the 'widgets_init' action hook.
*
* @uses register_sidebar()
* @uses get_categories()
* @uses get_cat_name()
*/
function category_sidebars() {
$categories = get_categories( array( 'hide_empty'=> 0,'taxonomy'=> APP_TAX_CAT ) );
foreach ( $categories as $category ) {
register_sidebar( array(
'name' => $category->cat_name,
'id' => $category->category_nicename . '-sidebar',
'description' => 'This is the ' . $category->cat_name . ' widgetized area',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
}
}
Great, all the subcategories show in the widgets admin, but I think that the second piece of code, which is put into the sidebar.php to call the appropriate sidebar on my category pages is not working for Classipress, this code was originally for wordpress.
Do anyone know what changes need to be made to the code below, which has to be placed into the sidebar.php to enable it to work with Classipress?
$sidebar_id = ( is_category() ) ? sanitize_title( get_cat_name( get_query_var( 'cat' ) ) ) . '-sidebar' : 'sidebar';
dynamic_sidebar( $sidebar_id );
I tried replacing dynamic_sidebar() function in that sidebar.php file with the code above but this did not work.
I would really like to get the sidebars on all my subcategories but am stuck with this code.
Any help would be welcome.
Thanks.