diff options
author | donncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36> | 2008-06-24 17:00:10 +0000 |
---|---|---|
committer | donncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36> | 2008-06-24 17:00:10 +0000 |
commit | 631c9bb4d60d242432052f56c00768392f42a392 (patch) | |
tree | 50d41b0248d5c5fb156c6d52020675208b77a3e6 /wp-includes/category-template.php | |
parent | a1fbe4e0694a66d7351e2f6280ab84568681e8e0 (diff) | |
download | wordpress-mu-631c9bb4d60d242432052f56c00768392f42a392.tar.gz wordpress-mu-631c9bb4d60d242432052f56c00768392f42a392.tar.xz wordpress-mu-631c9bb4d60d242432052f56c00768392f42a392.zip |
WP Merge to revision 8180
git-svn-id: http://svn.automattic.com/wordpress-mu/trunk@1336 7be80a69-a1ef-0310-a953-fb0f7c49ff36
Diffstat (limited to 'wp-includes/category-template.php')
-rw-r--r-- | wp-includes/category-template.php | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/wp-includes/category-template.php b/wp-includes/category-template.php index 1217276..69fc14d 100644 --- a/wp-includes/category-template.php +++ b/wp-includes/category-template.php @@ -539,4 +539,41 @@ function the_terms( $id, $taxonomy, $before = '', $sep = '', $after = '' ) { echo $return; } +/** + * Check if the current post has the given tag + * + * @package WordPress + * @since 2.6 + * + * @uses wp_get_object_terms() Gets the tags. + * + * @param string|int|array $tag Optional. The tag name/id/slug or array of them to check for + * @return bool True if the current post has the given tag, or any tag, if no tag specified + */ +function has_tag($tag = '') { + global $post; + $taxonomy = 'post_tag'; + + if ( !in_the_loop() ) return false; // in-the-loop function + + $post_id = (int) $post->ID; + + $terms = get_object_term_cache($post_id, $taxonomy); + if (empty($terms)) + $terms = wp_get_object_terms($post_id, $taxonomy); + if (empty($terms)) return false; + + if (empty($tag)) return (!empty($terms)); + + $tag = (array) $tag; + + foreach($terms as $term) { + if ( in_array( $term->term_id, $tag ) ) return true; + if ( in_array( $term->name, $tag ) ) return true; + if ( in_array( $term->slug, $tag ) ) return true; + } + + return false; +} + ?> |