Are you looking for a list of the current post’s categories and parents, or just a general list of categories? If the former, you can use get_category_parents()
. If you’re in The Loop, for example:
<?php
if( have_posts() ) :
while( have_posts() ) :
the_post();
// Post stuff
// ...
$cats = wp_get_post_categories( $post->ID );
foreach( $cats as $c ) {
$category_list=""; // initialize our text strings
$category_id_list="";
$display = false;
$sep = ', ';
$nice = false;
$parents = get_category_parents( $c, $display, $sep, $nice );
$_parents = explode( ',', $parents ); // convert the string to an array
$_parent_ids = array(); // initialize the array for the IDs
foreach( $_parents as $p ) {
$_parent_ids[] = get_cat_ID( $p );
}
// convert the $_parent_ids array to a string
$parent_ids = implode( ', ', $_parent_ids );
echo( "$parents $parent_ids" );
}
endwhile;
endif;
?>
[Edited: Cleaned up the code, and took advantage of PHP’s implode()
function]