Time after time, i have been forgetting this wordpress. You will know how important it is to output a category name in index page or in the blog post page (single.php)
Here are the 2 easy ways to output the category name.
Dont forget that this code will only work, only within the post loop.
1. Category with hyperlink
<?php the_category(', ') ?>
This will print ALL categories, separated by commas. If you want to change to another separator, you can replace the comma.
2. First Category Name
<?php $cat = get_the_category($post->id); echo $cat[0]->cat_name; ?>
This code will output only one category name.
Hope this small tip on wordpress code, helps!
Similar Posts:
- How to output parent and child categories in WordPress
- How to get parent category name in WordPress?
- How to show adsense on specific posts/pages in WordPress?
- How to get custom field value in WordPress?
- how to store and retrieve checkbox value in php?
- How to redirect when post submitted for review in WordPress
- Displaying HTML code in WordPress Posts!
- Fix: WordPress twenty ten theme shows no excerpt/summary!
- GD star rating issue replacing default 0 valueg
- 3 Must Do Things for WordPress Blog Starters

