More powerful version is is_tax(). Props filosofo, scribu. Adds $term parameter. Fixes #11904

git-svn-id: http://svn.automattic.com/wordpress/trunk@13486 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
dd32 2010-02-28 05:59:39 +00:00
parent c29b107102
commit dd78c07865
1 changed files with 26 additions and 7 deletions

View File

@ -221,24 +221,43 @@ function is_tag( $slug = '' ) {
} }
/** /**
* Whether the current page query has the given taxonomy slug or contains taxonomy. * Whether the current query is for the given taxonomy and/or term.
*
* If no taxonomy argument is set, returns true if any taxonomy is queried.
* If the taxonomy argument is passed but no term argument, returns true
* if the taxonomy or taxonomies in the argument are being queried.
* If both taxonomy and term arguments are passed, returns true
* if the current query is for a term contained in the terms argument
* which has a taxonomy contained in the taxonomy argument.
* *
* @since 2.5.0 * @since 2.5.0
* @uses $wp_query * @uses $wp_query
* *
* @param string|array $slug Optional. Slug or slugs to check in current query. * @param string|array $taxonomy Optional. Taxonomy slug or slugs to check in current query.
* @param int|array|string $term. Optional. A single or array of, The term's ID, Name or Slug
* @return bool * @return bool
*/ */
function is_tax( $slug = '' ) { function is_tax( $taxonomy = '', $term = '' ) {
global $wp_query; global $wp_query, $wp_taxonomies;
if ( !$wp_query->is_tax ) $queried_object = $wp_query->get_queried_object();
$tax_array = array_intersect(array_keys($wp_taxonomies), (array) $taxonomy);
$term_array = (array) $term;
if ( ! ( $wp_query->is_tax || $wp_query->is_category || $wp_query->is_tag ) )
return false; return false;
if ( empty($slug) ) if ( empty( $taxonomy ) )
return true; return true;
return in_array( get_query_var('taxonomy'), (array) $slug ); if ( empty( $term ) ) // Only a Taxonomy provided
return isset($queried_object->taxonomy) && count( $tax_array ) && in_array($queried_object->taxonomy, $tax_array);
return isset($queried_object->term_id) &&
count(array_intersect(
array($queried_object->term_id, $queried_object->name, $queried_object->slug),
$term_array
));
} }
/** /**