Created
January 17, 2012 16:14
-
-
Save benbalter/1627277 to your computer and use it in GitHub Desktop.
Faceted Search Page Title
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Replaces default template title with faceted search "breadcrumbs" describing the instant query | |
* @author Benjamin J. Balter | |
* @package Faceted_Search_Widget | |
*/ | |
//function to be placed in theme's functions.php file... | |
function faceted_search_page_title( ) { | |
global $wp_query; | |
$output = array(); | |
foreach ( $wp_query->query as $key=>$value ) { | |
if ( $key == 'post_type' ) | |
continue; | |
foreach ( explode('+', $value ) as $search) { | |
$tax = get_taxonomy( $key ); | |
$term = get_term_by('slug', $search, $tax->name); | |
$link = $tax->labels->singular_name . ': ' . $term->name; | |
$link .= ' <a class="remove_faceted_search" id="remove_{$tax->name}" href="' . esc_url( remove_query_arg( $tax->query_var ) ) . '">remove</a>'; | |
$output[] = $link; | |
} | |
} | |
return implode(', <Br />', $output); | |
} | |
//in your themes taxonomy.php file (or other template file)... | |
//note: if child theme, copy template from parent theme to child and modify | |
//change the page's default title function (most likely something like...) | |
<h1 class="page-title"><?php printf( __( 'Category Archives: %s', 'twentyeleven' ), '<span>' . single_cat_title( '', false ) . '</span>' ); ?></h1> | |
//To | |
<h1 class="page-title"><?php | |
if ( function_exists( 'faceted_search_page_title' ) ) | |
echo faceted_search_page_title(); | |
else | |
printf( __( 'Category Archives: %s', 'twentyeleven' ), '<span>' . single_cat_title( '', false ) . '</span>' ); | |
?></h1> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment