简体   繁体   中英

Adding class “current_page_item” for custom post type category list(note: the category is belong in custom taxonomy)

I have this code:

<?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>

it display the list of category with permalink. so I want if I click one of the category in the list the list I click must highlight so visitors identify that they are in that specific category.

Have you tried the wp_list_categories() function?

From the Codex: http://codex.wordpress.org/Template_Tags/wp_list_categories

Another option is to run a walker function to ouput a menu:

https://wordpress.stackexchange.com/questions/115526/add-class-to-items-in-wp-list-categories

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM