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!