As you probably know, to get the category list in WordPress, you use:
<ul>
<?php wp_list_categories('orderby=name&show_count=1&title_li='); ?>
</ul>
Is it possible to get it without <li>
, and display link counts of each category inside the <a>
tag itself?
For example, I want to use this structure for categories:
<nav>
<a href="?cat=1">Arabesque (3)</a>
<a href="?cat=2">Business (5)</a>
</nav>
instead of this typical one:
<nav>
<ul>
<li><a href="?cat=1">Arabesque</a> (3)</li>
<li><a href="?cat=2">Business</a> (5)</li>
</ul>
</nav>
The best way is to use a filter:
To move the post count inside the
a
tag, use this snippet in your functions.php file:Source: https://gist.github.com/blainerobison/1f1e59c99f5c9a78b93d
Got it from GitHub https://gist.github.com/blainerobison/1f1e59c99f5c9a78b93d
Works Perfectly
/**
* Move Category Post Counts Inside Link
*
* filters wp_list_categories()
*
* @param string $links link html output
* @return string
*/
function prefix_move_category_count( $links ) {
}
add_filter( ‘wp_list_categories’, ‘prefix_move_category_count’ );
/**
* Move Archive Post Counts Inside Link
*
* filters get_archives_link()
*
* @param string $links link html output
* @return string
*/
function prefix_move_archive_count($links) {
}
add_filter( ‘get_archives_link’, ‘prefix_move_archive_count’ );