我有一个自定义的类别按钮,每个按钮都链接并在同一页回显特定类别。我的目标是在活动链接上放置活动背景悬停颜色。以下是我目前的代码:
<?php
$args = array(
\'orderby\' => \'slug\',
\'order\' => \'ASC\',
\'parent\' => 0,
\'hide_empty\' => false
);
$categories = get_categories( $args );
foreach( $categories as $category ){
echo \'<li><a class="ctg" href="\' . get_category_link( $category->term_id ) .\' ">\' . $category->name . \'</a></li>\';
}
?>
和我的css:
.ctg:hover {
background: #A6EBF2;
}
.ctg:active {
background-color: #A6EBF2;
}
非常感谢您的帮助。
以下是我迄今为止编写的代码:
$categories = get_categories( $args );
foreach( $categories as $category ){
$the_category_id = $category->term_id;
if(function_exists(\'rl_color\')){
$rl_category_color = rl_color($the_category_id);
} else {
$rl_category_color = \'#a6ebf2\'; // bg color
}
echo \'<li><a href="\'. get_category_link( $category->term_id ) .\'" class="\' . $category->slug . \'" title="View all posts in \'. esc_attr($category->name) . \'" style="background-color:\' . $rl_category_color .\' ">\' . $category->name . \'</a></li>\';