From b14b19b3ff6e997b2bdd11225f9343649e163e34 Mon Sep 17 00:00:00 2001 From: Matt Mullenweg Date: Tue, 18 May 2004 08:18:38 +0000 Subject: [PATCH] Simple function to check if a post is in a category. git-svn-id: https://develop.svn.wordpress.org/trunk@1304 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/template-functions-category.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/wp-includes/template-functions-category.php b/wp-includes/template-functions-category.php index 34c767e0f6..42302a1f32 100644 --- a/wp-includes/template-functions-category.php +++ b/wp-includes/template-functions-category.php @@ -412,4 +412,17 @@ function list_cats($optionall = 1, $all = 'All', $sort_column = 'ID', $sort_orde } echo apply_filters('list_cats', $thelist); } + +function in_category($category) { // Check if the current post is in the given category + global $post, $category_cache; + $cats = ''; + foreach ($category_cache[$post->ID] as $cat) : + $cats[] = $cat->category_id; + endforeach; + + if ( in_array($category, $cats) ) + return true; + else + return false; +} ?> \ No newline at end of file