Changeset 15677
- Timestamp:
- 10/01/2010 05:44:53 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/category-template.php
r15590 r15677 249 249 * @since 1.2.0 250 250 * 251 * @uses is_object_in_term()251 * @uses has_term() 252 252 * 253 253 * @param int|string|array $category Category ID, name or slug, or array of said. … … 255 255 * @return bool True if the current post is in any of the given categories. 256 256 */ 257 function in_category( $category, $_post = null ) { 258 if ( empty( $category ) ) 259 return false; 260 261 if ( $_post ) { 262 $_post = get_post( $_post ); 263 } else { 264 $_post =& $GLOBALS['post']; 265 } 266 267 if ( !$_post ) 268 return false; 269 270 $r = is_object_in_term( $_post->ID, 'category', $category ); 271 if ( is_wp_error( $r ) ) 272 return false; 273 return $r; 257 function in_category( $category, $post = null ) { 258 return has_term( $category, 'category', $post ); 274 259 } 275 260 … … 972 957 } 973 958 959 960 /** 961 * Check if the current post has any of given category. 962 * 963 * @since 3.1.0 964 * 965 * @uses has_term() 966 * 967 * @param string|int|array $tag Optional. The category name/term_id/slug or array of them to check for. 968 * @param int|object $post Optional. Post to check instead of the current post. 969 * @return bool True if the current post has any of the given categories (or any category, if no category specified). 970 */ 971 function has_category( $category = '', $post = null ) { 972 return has_term( $category, 'category', $post ); 973 } 974 974 975 /** 975 976 * Check if the current post has any of given tags. … … 985 986 * @since 2.6.0 986 987 * 988 * @uses has_term() 989 * 990 * @param string|int|array $tag Optional. The tag name/term_id/slug or array of them to check for. 991 * @param int|object $post Optional. Post to check instead of the current post. (since 2.7.0) 992 * @return bool True if the current post has any of the given tags (or any tag, if no tag specified). 993 */ 994 function has_tag( $tag = '', $post = null ) { 995 return has_term( $tag, 'post_tag', $post ); 996 } 997 998 /** 999 * Check if the current post has any of given terms. 1000 * 1001 * The given terms are checked against the post's terms' term_ids, names and slugs. 1002 * Terms given as integers will only be checked against the post's terms' term_ids. 1003 * If no terms are given, determines if post has any terms. 1004 * 1005 * @since 3.1.0 1006 * 987 1007 * @uses is_object_in_term() 988 1008 * 989 * @param string|int|array $tag Optional. The tag name/term_id/slug or array of them to check for. 990 * @param int|object $_post Optional. Post to check instead of the current post. (since 2.7.0) 991 * @return bool True if the current post has any of the the given tags (or any tag, if no tag specified). 992 */ 993 function has_tag( $tag = '', $_post = null ) { 994 if ( $_post ) { 995 $_post = get_post( $_post ); 996 } else { 997 $_post =& $GLOBALS['post']; 998 } 999 1000 if ( !$_post ) 1009 * @param string|int|array $term Optional. The term name/term_id/slug or array of them to check for. 1010 * @param int|post object Optional. Post to check instead of the current post. 1011 * @since 2.7.0 1012 * @return bool True if the current post has any of the given tags (or any tag, if no tag specified). 1013 */ 1014 function has_term( $term = '', $taxonomy = '', $post = null ) { 1015 $post = get_post($post); 1016 1017 if ( !$post ) 1001 1018 return false; 1002 1019 1003 $r = is_object_in_term( $ _post->ID, 'post_tag', $tag);1020 $r = is_object_in_term( $post->ID, $taxonomy, $term ); 1004 1021 if ( is_wp_error( $r ) ) 1005 1022 return false; 1023 1006 1024 return $r; 1007 1025 }
Note: See TracChangeset
for help on using the changeset viewer.