From 9735b962ba2559ad95d293413ee2c7469e0b68ae Mon Sep 17 00:00:00 2001 From: westi Date: Wed, 27 Feb 2008 18:25:25 +0000 Subject: [PATCH] A better in_category which supports category names that are all numbers. git-svn-id: http://svn.automattic.com/wordpress/trunk@7064 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/category-template.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/wp-includes/category-template.php b/wp-includes/category-template.php index ba47b677f..ca1299d43 100644 --- a/wp-includes/category-template.php +++ b/wp-includes/category-template.php @@ -167,12 +167,24 @@ function get_the_category_list($separator = '', $parents='', $post_id = false) { return apply_filters('the_category', $thelist, $separator, $parents); } +/* + * in_category() - Checks whether the current post is within a particular category + * + * This function checks to see if the post is within the supplied category. The categoy + * can be specified by number or name and will be checked as a name first to allow for categories with numeric names. + * Note: Prior to v2.5 of WordPress category names where not supported. + * + * @since 1.2.0 + * + * @param int|string $category + * @return bool true if the post is in the supplied category +*/ function in_category( $category ) { // Check if the current post is in the given category global $post; - if ( !is_numeric($category) ) { - $category = get_cat_ID($category); - } + $cat_ID = get_cat_ID($category); + if (0 != $cat_ID) + $category = $cat_ID; $categories = get_object_term_cache($post->ID, 'category'); if ( false === $categories )