Ashley Cameron Design

Ashley Cameron Design

Shop the Creative Design Market

Good morning

Query taxonomy into dropdown menu with post count for WordPress

SnippetsWordPress

About a 1 minute read

"We cannot solve our problems with the same thinking we used when we created them."

Albert Einstein


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<!-- !Projects Dropdown -->
    <?php $args = array( 'taxonomy' => 'projects', 'orderby' => 'name', 'show_count' => 1, 'pad_counts' => 1, 'hierarchical' => 1, 'title_li' => '' ); ?>
    <div class="btn-group">
      <button type="button" class="btn btn-default"><i class="fa fa-briefcase"></i> Project</button>
      <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
        <span class="caret"></span>
        <span class="sr-only">Toggle Dropdown</span>
      </button>
      <ul class="dropdown-menu" role="menu" aria-labelledby="projects">
        <?php $categories=get_terms('projects', $args);
            foreach($categories as $category) {
                echo '<li><a href="' . get_term_link( $category ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name. ' ('. $category->count . ')</a> </li> ';
            } ?>
      </ul>
    </div>