Say "Hello!"

  • This field is for validation purposes and should be left unchanged.

Query categories into dropdown menu with post count for WordPress


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>

Back to Snippets Follow me on GitHub

Ashley Cameron logo
Blog