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:
parent
08a1579b0c
commit
79de611ce9
|
@ -412,4 +412,17 @@ function list_cats($optionall = 1, $all = 'All', $sort_column = 'ID', $sort_orde
|
||||||
}
|
}
|
||||||
echo apply_filters('list_cats', $thelist);
|
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;
|
||||||
|
}
|
||||||
?>
|
?>
|
Loading…
Reference in New Issue