我有这段代码:
<?php
//list terms in a given taxonomy (useful as a widget for twentyten)
$taxonomy = 'advice-cat';
$tax_terms = get_terms($taxonomy);
?>
<ul>
<?php
foreach ($tax_terms as $tax_term) {
echo '<li>' . '<a href="' . esc_attr(get_term_link($tax_term, $taxonomy)) . '" title="' . sprintf( __( "View all posts in %s" ), $tax_term->name ) . '" ' . '>' . $tax_term->name.'</a></li>';
}
?>
</ul>
它显示包含永久链接的类别列表。所以我想如果点击列表中的某个类别,我点击的列表必须突出显示,以便访问者确定他们属于该特定类别。
答案 0 :(得分:1)
您是否尝试过wp_list_categories()函数?
来自法典:http://codex.wordpress.org/Template_Tags/wp_list_categories
另一个选择是运行一个walker函数来输出一个菜单:
https://wordpress.stackexchange.com/questions/115526/add-class-to-items-in-wp-list-categories