Skip to content

Instantly share code, notes, and snippets.

@morgyface
Last active July 15, 2016 21:49
Show Gist options
  • Select an option

  • Save morgyface/870ee5a94c871453499c864e4bbf5a92 to your computer and use it in GitHub Desktop.

Select an option

Save morgyface/870ee5a94c871453499c864e4bbf5a92 to your computer and use it in GitHub Desktop.
WordPress | Comma seperated list of all categories assigned to a post without links
<?php
if ( has_category() ) {
echo '<span>';
$categories = get_the_category();
$total = count( $categories );
$catcount = 1;
foreach( $categories as $category ) {
$catname = $category->cat_name;
echo $catname;
if ( $catcount != $total ) {
echo ', '; // if NOT last print a comma
}
$catcount++;
} // end foreach
echo '</span>';
} // end if has_category
?>
@morgyface
Copy link
Author

morgyface commented Jul 15, 2016

Just the categories assigned to a post

I rarely need to do this, but when I do it always seems a struggle to find out how.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment