WordPress.org

Make WordPress Core

Changeset 7064


Ignore:
Timestamp:
02/27/2008 06:25:25 PM (12 years ago)
Author:
westi
Message:

A better in_category which supports category names that are all numbers.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/category-template.php

    r7030 r7064  
    168168}
    169169
     170/*
     171 * in_category() - Checks whether the current post is within a particular category
     172 *
     173 * This function checks to see if the post is within the supplied category.  The categoy
     174 * can be specified by number or name and will be checked as a name first to allow for categories with numeric names.
     175 * Note: Prior to v2.5 of WordPress category names where not supported.
     176 *
     177 * @since 1.2.0
     178 *
     179 * @param int|string $category
     180 * @return bool true if the post is in the supplied category
     181*/
    170182function in_category( $category ) { // Check if the current post is in the given category
    171183    global $post;
    172184
    173     if ( !is_numeric($category) ) {
    174         $category = get_cat_ID($category);
    175     }
     185    $cat_ID = get_cat_ID($category);
     186    if (0 != $cat_ID)
     187        $category = $cat_ID;
    176188   
    177189    $categories = get_object_term_cache($post->ID, 'category');
Note: See TracChangeset for help on using the changeset viewer.