php - Change widget's CSS class names for different category pages in WordPress -


I want to change the class names of sidebar widgets on each separate category page of WordPress and I find out the best way to do this Functions in functions.php with all the conditions must be created and returned the required class names. I again called the function in the list tags of register_sidebar function.

  if {function_exists ('register_sidebar')) {register_sidebar (array ('before_widget' => 
class = "sidebar module" & gt; ', after_widget' = & Lt; / li & gt; & lt ;! - End module - & gt; ',' before_title '= & gt; & lt; h2 class = "moduleTitle"' .set_widget_title_color (). '& Gt; ',' after_title '= & gt;' ',)); } Function set_widget_title_color (if (is_category ('technology')) {$ color = "catNavColor1_active"}} Otherwise (is_category ('Gadgets')) {$ color = "catNavColor2_active";} Otherwise (is_category ('social media' } {$ Color = "catNavColor3_active"}} {$ color = "catNavColor3_active";} Otherwise (is_category ('gaming')) {$ color = "catNavColor4_active"}} Otherwise (is_category ('other')) $ $ COLON ;}

does not work for any reason. Please help

thanks

I think that register_sidebars is said very quickly in this process, when the category Not even defined. Have you tried to implement the filter in the dynamic_sidebar_params ? I did not find anything in the WordPress codex, but I found out that there is another question on this topic. / P>

This only works if you apply the sidebar in your widget by using dynamic_sidebar , because this function call dynamic_sidebar_params filter. If you have a static widget (do not use the widget admin page defined in your template), then you should call your function in that template code, such as:

   

Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -