Amit

WordPress list categories with post count

if you looking for a way to list all categories with all post count. use below code.

<ul class="categories">
	<?php
	$categories = get_categories( array(
		'orderby' => 'name',
		'parent'  => 0
	) );

	if ( $categories && !is_wp_error( $categories ) ) :
	$i=0;
		foreach ( $categories as $categori ) { ?>
		<li>
			<a href="<?php echo get_category_link( $categori->term_id ); ?>" title="<?php echo $categori->name; ?>"><i class="fa fa-angle-double-right" aria-hidden="true"></i> <?php echo $categori->name; ?> <span><?php echo $categori->count; ?></span></a>
		</li>
	<?php $i++; };
	endif; ?>
</ul>

Last Update on:March 5th, 2023 at 5:19 pm


Bootstrap 5 navwalker for wordpress
Previous post