Ashley Cameron Design

Ashley Cameron Design

Shop the Creative Design Market

Goodnight

Query taxonomy into dropdown menu with post count for WordPress

SnippetsWordPress

About a 1 minute read

"This is the real secret of life — to be completely engaged with what you are doing in the here and now. And instead of calling it work, realize it is play."

Alan Watts


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>