Simple function to check if a post is in a category.

git-svn-id: http://svn.automattic.com/wordpress/trunk@1304 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
saxmatt 2004-05-18 08:18:38 +00:00
parent 08a1579b0c
commit 79de611ce9
1 changed files with 13 additions and 0 deletions

View File

@ -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;
}
?>