Skip to main content
added 80 characters in body
Source Link
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 print_r($category):

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

to view the array of objects that are returned.

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 print_r($category) to view the array of objects that are returned.

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.

Source Link
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 print_r($category) to view the array of objects that are returned.