mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-23 01:27:36 +01:00
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:
parent
c29b107102
commit
dd78c07865
@ -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
|
||||
* @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
|
||||
*/
|
||||
function is_tax( $slug = '' ) {
|
||||
global $wp_query;
|
||||
function is_tax( $taxonomy = '', $term = '' ) {
|
||||
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;
|
||||
|
||||
if ( empty($slug) )
|
||||
if ( empty( $taxonomy ) )
|
||||
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
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user