Get post categories in while loop


<?php
$categories = get_the_category();
$separator = ‘, ‘;
$output = ”;
if ( ! empty( $categories ) ) {
foreach( $categories as $category ) {
$output .= ‘<a href=”‘ .get_category_link( $category->term_id ). ‘” >’ . $category->name . ‘</a>’ . $separator;
}
echo trim( $output, $separator );
}
?>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s