Skip to content

Instantly share code, notes, and snippets.

@anatol06
Last active May 6, 2018 21:53
Show Gist options
  • Save anatol06/da81e1d5d4be143f3397009d38828d8e to your computer and use it in GitHub Desktop.
Save anatol06/da81e1d5d4be143f3397009d38828d8e to your computer and use it in GitHub Desktop.
Get the list of categories to which the article belongs
<?php // Get the list of categories to which the article belongs
$categories = get_the_category();
$separator = ", ";
$output = '';
if($categories) {
foreach($categories as $category) {
$output .= '<a href="'.
get_category_link($category->term_id).'">'.
$category->cat_name .'</a>'.$separator;
// $output .= $category->cat_name . $separator;
}
}
echo trim($output, $separator);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment