[英]Adding class “current_page_item” for custom post type category list(note: the category is belong in custom taxonomy)
我有以下代碼:
<?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>
它顯示帶有永久鏈接的類別列表。 因此,如果我單擊列表中的一個類別,我想單擊的列表必須突出顯示,以便訪問者識別出他們屬於該特定類別。
您是否嘗試過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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.