Skip to main content
2 of 2
added 80 characters in body
VicePrez
  • 678
  • 5
  • 15

You could use get_the_category() to do that.

Example:

<?php

$category = get_the_category(); 

// use this to echo the slug
echo $category[0]->slug;

// use this to echo the cat id
echo $category[0]->cat_ID;

// if you've got multiple categories you can run a foreach loop like so
foreach ( $category as $cat ) :

    echo '<li>' . $cat->name . '</li>';

endforeach;

?>

You could use:

<?php
    echo '<pre>';
    print_r($category);
    echo '</pre>';
?>

to view the array of objects that are returned.

VicePrez
  • 678
  • 5
  • 15