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

"Learn from yesterday, live for today, hope for tomorrow. The important thing is not to stop questioning."

Albert Einstein


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>