Say "Hello!"

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

Query taxonomy into dropdown menu with post count for WordPress

Web Hosting at Bluehost Affiliate Disclosure

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>

Back to Snippets Follow me on GitHub

Ashley Cameron logo
Blog