Last active
July 15, 2016 21:49
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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 | |
| ?> |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.