How to add sidebar to category pages

Hello, I have a newspaper website. Ive created different sidebars for each category. How do I get the sidebar to display on the corresponding category? This is the site and link to the page im trying to edit: http://fireisland-news.com/category/columns/cherrygrove-columns/

And this is the page that its supposed to look like: http://fireisland-news.com/columns/cherry-grove-news/
I want to also be able to add the header image like I have on this page. I created this page with a plugin but the only drawback is that there is no pagination. So if adding pagination to this page is possible then I don’t need to do the previously mentioned sidebar thing and header.

Hope this isnt too confusing.
Thanks for your help!!!
Rena

Hi Rena,

To create different sidebars for each category, please add the following code under functions.php file locates in your child theme:

add_filter( 'ups_sidebar', 'x_category_sidebar' );
function x_category_sidebar($sidebar){
  if( is_category( 1 ) ){
	return 'ups-sidebar-category-1-sidebar';
  } else if( is_category( 2 ) ){
	return 'ups-sidebar-category-2-sidebar';
  } else if( is_category( 3 ) ){
	return 'ups-sidebar-category-3-sidebar';
  } else if( is_category( 4 ) ){
	return 'ups-sidebar-category-4-sidebar';
  }
  return $sidebar;
}

To add the banner to the category page, you can try with the global block feature:

Add the following code to your functions.php file as well:

add_action( 'x_before_view_global__index', 'x_print_category_banner' );
function x_print_category_banner(){
	if( is_category( 1 ) ) {
		echo do_shortcode( '[cs_gb id=123' );
	} else if( is_category( 2 ) ) {
		echo do_shortcode( '[cs_gb id=234' );
	} else if( is_category( 3 ) ) {
		echo do_shortcode( '[cs_gb id=456' );
	} else if( is_category( 4 ) ) {
		echo do_shortcode( '[cs_gb id=789' );
	} 
}

Hope that helps and thank you for understanding.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.