Deprecated: Function seems_utf8 is deprecated since version 6.9.0! Use wp_is_valid_utf8() instead. in /home/dplugins-code/htdocs/code.dplugins.com/wp-includes/functions.php on line 6131

Deprecated: Function seems_utf8 is deprecated since version 6.9.0! Use wp_is_valid_utf8() instead. in /home/dplugins-code/htdocs/code.dplugins.com/wp-includes/functions.php on line 6131
List categories and taxonomies with class active – Code DPlugins

List categories and taxonomies with class active

List of categories for posts with link to archive and wrapped in classes

<ul>
    <?php wp_list_categories( array(
        'orderby'    => 'name',        
  		'title_li' => '',
        'hide_title_if_empty' => true,
    ) ); ?> 
</ul>

To enable it for taxonomies add this line and replace ‘produckte’ with your taxonomy slug

'taxonomy'  => 'produkte',

And on the end you will get this for custom categories ( taxonomies)

<ul>
    <?php wp_list_categories( array(
		'taxonomy'  => 'produkte',
        'orderby'    => 'name',        
  		'title_li' => '',
        'hide_title_if_empty' => true,
    ) ); ?> 
</ul>

Here is preview of HTML output:

<ul>
	<li class="cat-item cat-item-1 current-cat">
		<a aria-current="page" href="link">Cat name 1</a>
	</li>
	<li class="cat-item cat-item-2">
		<a aria-current="page" href="link">Cat name 2</a>
	</li>
	<li class="cat-item cat-item-3">
		<a aria-current="page" href="link">Cat name 3</a>
	</li>
</ul>
Click to Copy