Ashley Cameron Design

Ashley Cameron Design

Shop the Creative Design Market

Goodnight

Query categories into dropdown menu with post count for WordPress

SnippetsWordPress

About a 1 minute read

"The art of living… is neither careless drifting on the one hand nor fearful clinging to the past on the other. It consists in being sensitive to each moment, in regarding it as utterly new and unique, in having the mind open and wholly receptive."

Alan Watts


1
2
3
4
5
6
7
8
9
<!-- !Categories Dropdown -->
        <ul class="dropdown-menu" role="menu" aria-labelledby="categories">
            <?php $args=array( 'orderby' => 'name', 'order' => 'ASC', 'show_count' => 1 );
            $categories=get_categories($args);
              foreach($categories as $category) {
                echo '<li><a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' .  $category->name. ' ('. $category->count . ')</a> </li> ';
                } ?>
        </ul>
    </div>