Hi, in Wordpress on a post how can I get the name of the category it belongs to (each post will only have one category on my website).
A:
The version of wordpresss you're using is very much relevant for your question, but a good place to start would be the wordpress codex where you can find for example the documentation of this function.
It is also important to know whether your code will be placed within the infamous loop (which would be the case if you're editing the post template) or not (for example, if your code goes at the sidebar, header, etc).
Assuming the first case, and taking the example from the manual, you could use:
<?php
$categories = get_the_category();
// there is only one, so extract the first from the array
$category = $category[0];
?>
Javier
2010-04-07 11:58:44
Thanks for your response, It's not actually intended to go within the loop, It's going in header.php
Probocop
2010-04-07 13:21:12
A:
These can go in header.php for generating meta tags, page titles, etc.
<?php echo trim(strip_tags(category_description())); ?>
<?php echo single_cat_title(''); ?>
songdogtech
2010-04-07 13:34:54