WordPressのさまざまなカテゴリページごとにサイドバーウィジェットのクラス名を変更したいのですが、これを行う最善の方法は、functions.phpですべての条件を使用して関数を作成し、必要なクラス名を返すことです。次に、register_sidebar関数のリストタグで関数を呼び出しました。
if (function_exists('register_sidebar')) {
register_sidebar(array(
'before_widget' => '<li class="sidebarModule">',
'after_widget' => '</li><!-- end module -->',
'before_title' => '<h2 class="moduleTitle "'.set_widget_title_color().'>',
'after_title' => '</h2>',
));
}
function set_widget_title_color() {
if(is_category('technology')) {
$color = "catNavColor1_active";
} elseif(is_category('gadgets')) {
$color = "catNavColor2_active";
} elseif(is_category('social-media')) {
$color = "catNavColor3_active";
} elseif(is_category('gaming')) {
$color = "catNavColor4_active";
} elseif(is_category('other')) {
$color = "catNavColor5_active";
}
return $color;
}
何らかの理由で上記は機能しません。助けてください
ありがとう