Skip to content

Instantly share code, notes, and snippets.

@billerickson
Created January 25, 2012 16:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save billerickson/1676961 to your computer and use it in GitHub Desktop.
Save billerickson/1676961 to your computer and use it in GitHub Desktop.
<?php
add_action( 'genesis_before_loop', 'be_recipe_archive_intro', 15 );
/**
* Intro - Recipe Archive
* @author Bill Erickson
*
* (in archive-recipes.php)
*/
function be_recipe_archive_intro() {
echo '<h4>Cocktail Recipes';
be_navigation_count( 'Recipes' );
echo '</h4>';
echo '<div class="archive-intro">';
echo '<div class="search"><label>Search by Name or Ingredients:</label>';
global $form_type;
$form_type = 'recipe';
get_search_form();
$form_type = '';
echo '</div><!-- search -->';
be_sort_by();
echo '<div class="filter-category"><label>Category:</label> ';
echo be_taxonomy_select_and_filter( 'base', 'recipe' );
echo '</div><!-- .filter-category-->';
echo '<div class="filter-name"><label>Name:</label> ';
echo be_taxonomy_select_and_filter( 'name-range', 'recipe' );
echo '</div>';
echo '</div>';
echo '<div class="dot-divider"></div>';
}
add_filter( 'be_all_taxonomy_filters', 'be_recipe_tax_filters' );
/**
* Include taxonomy filters in 'all' list
* @author Bill Erickson
*
* @param array $all
* @return array
*/
function be_recipe_tax_filters( $all ) {
$brands = array( 'filter', 'base', 'name-range' );
return array_merge( $all, $brands );
}
/**
* Taxonomy Select and Filter
* @author Bill Erickson
*
* @param string $taxonomy_slug
* @return string $output
*/
function be_taxonomy_select_and_filter( $taxonomy_slug, $post_type = false ) {
$terms = get_terms( $taxonomy_slug, array( 'hide_empty' => false ) );
if( false == $terms )
return false;
$form = '<form action="' . get_bloginfo('url') . '" method="get"><div>';
// Include existing query vars
$other_filters = array_unique( apply_filters( 'be_all_taxonomy_filters', array( ) ) );
foreach( $other_filters as $other_filter )
if( get_query_var( $other_filter ) )
$form .= '<input type="hidden" name="' . $other_filter . '" value="' . get_query_var( $other_filter ) . '" />';
// Build the select menu
$form .= '<select name="' . $taxonomy_slug . '" id="' . $taxonomy_slug . '" class="postform" onchange="return this.form.submit()">';
// If the select has been used already, show the value
$active = false;
if( get_query_var( $taxonomy_slug ) ) {
$active = get_term_by( 'slug', get_query_var( $taxonomy_slug ), $taxonomy_slug );
$form .= '<option value="' . $active->slug . '">' . $active->name . '</option><option value="all">All</option>';
}else {
$form .= '<option value="-1">Select</option>';
}
// List all the terms (excluding active)
foreach( $terms as $term ) {
if( $term->term_id !== $active->term_id )
$form .= '<option value="' . $term->slug . '">' . $term->name . '</option>';
}
$form .= '</select>';
if( $post_type )
$form .= '<input type="hidden" name="post_type" value="' . $post_type . '" />';
$form .= '<noscript><div><input type="submit" value="View" /></div></noscript>';
$form .= '</div></form>';
return $form;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment