Skip to content

Instantly share code, notes, and snippets.

@abelsaad
Created June 23, 2021 08:34
Show Gist options
  • Save abelsaad/4d68fcce938170c66fff9858980ecf3c to your computer and use it in GitHub Desktop.
Save abelsaad/4d68fcce938170c66fff9858980ecf3c to your computer and use it in GitHub Desktop.
Get Category
// A nice, way to display linked categories is by using a comma as separator
<?php the_category( ', ' ); ?>
// The separator will not be added after the last linked category. By using the following reasoning, each of the linked categories can also be enclosed, for example, in a <div> element:
<?php the_category( '</div><div>' ); ?>
// or to use the linked categories in a sentence:
This post has <?php the_category( ', ' ); ?> as categories.
// The simplest way to display a category, or a list of categories, without links is by using the following code:
<?php
// to display categories without a link
foreach ( ( get_the_category() ) as $category ) {
echo $category->cat_name . ' ';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment