I have been looking at how to extract the category names and other post information in a wordpress template.
It can be useful to be able to extract these items from each post so that we can base category images or just display the first category in the template. Using the following code i have been able to extract this information using wordpress in-built functions.
Here is how to extract the first category id from each post if used in the page loop:
$category = get_the_category();
$currentcat = $category[0]->cat_ID;
Here is one you can use out side of the loop:
global $post;
$categories = get_the_category($post->ID);
$currentcat = $category[0]->cat_ID;
Extracting the name of the category out side of the page loop.
global $post;
$categories = get_the_category($post->ID);
$currentcat = $category[0]->cat_name;





kruxor on July 15th, 2010 