Skip to content

Instantly share code, notes, and snippets.

@kellenmace
Created September 23, 2016 20:21
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kellenmace/f6de4fb74cb4823dc77fb7bed0f9c501 to your computer and use it in GitHub Desktop.
Save kellenmace/f6de4fb74cb4823dc77fb7bed0f9c501 to your computer and use it in GitHub Desktop.
WordPress Taxonomy Dropdown Template
<div class="tools-dropdown">
<form id="tool-category-select" class="tool-category-select" method="get">
<?php
// Create and display the dropdown menu.
wp_dropdown_categories(
array(
'orderby' => 'NAME', // Order the items in the dropdown menu by their name.
'taxonomy' => 'tools', // Only include posts with the taxonomy of 'tools'.
'name' => 'tools', // Change this to the
'show_option_all' => 'All Tools', // Text the dropdown will display when none of the options have been selected.
'selected' => km_get_selected_taxonomy_dropdown_term(), // Set which option in the dropdown menu is the currently selected one.
) );
?>
<input type="submit" value="View" />
</form>
</div>
<section id="tools-listing">
<?php $tools_in_taxonomy_term = km_get_tools_in_taxonomy_term(); ?>
<!-- If posts were found, -->
<?php if ( $tools_in_taxonomy_term->have_posts() ) : ?>
<!-- Loop through every post. -->
<?php while ( $tools_in_taxonomy_term->have_posts() ) : $tools_in_taxonomy_term->the_post(); ?>
<!-- Display each post's title and content - you can change this section to display whatever post content you want. -->
<article class="tool-entry">
<h1><?php the_title(); ?></h1>
<p><?php the_content(); ?></p>
</article>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
</section>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment