Ashley Cameron Design

Ashley Cameron Design

Shop the Creative Design Market

Good morning

Query categories into dropdown menu with post count for WordPress

SnippetsWordPress

About a 1 minute read

"There is one thing one has to have: either a soul that is cheerful by nature, or a soul made cheerful by work, love, art, and knowledge."

Friedrich Nietzsche


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>