Say I have a post called Hello World in Wordpress and I'm directly viewing this page, how would I go about finding the category of "Hello World" and displaying it?
+1
A:
Use get_the_category()
like this:
<?php
foreach((get_the_category()) as $category) {
echo $category->cat_name . ' ';
}
?>
It returns a list because a post can have more than one category.
The documentation also explains how to do this from outside the loop.
RichieHindle
2009-06-03 17:12:34
many thanks Richie
Keith Donegan
2009-06-03 17:27:02
A:
You can use
<?php the_category(', '); ?>
which would output them in a comma separated list.
You can also do the same for tags as well:
<?php the_tags('<em>:</em>', ', ', ''); ?>
Joseph
2009-06-03 17:15:48
You should reply under the posted answer and not here for things like this.
Keith Donegan
2009-12-29 21:43:47