Search code examples
phpwordpresscategorieswp-list-categories

wp_list_categories to show categories for current post


I want to show only categories name and link of the current post page. For example i have a post lets say "test123" and I have linked the post with 2 categories "ab","bc". However I have 5 different categories. So I want to show only 2 categories "ab","bc" when user goes to the "test123" page.

Please see my code below it is showing all the categories but I want to show only categories which are linked with the current post page.

wp_list_categories( 'number=5' ); ?>

Solution

  • <?php the_category(); ?> 
    

    or, if you want more options:

    <?php the_category( $separator, $parents, $post_id ); ?> 
    

    This will do the trick. It can also be used like this:

    <?php $catArr = get_the_category( $id ); ?>
    

    Reference:

    http://codex.wordpress.org/Template_Tags/the_category http://codex.wordpress.org/Function_Reference/get_the_category