Created
June 23, 2021 08:34
-
-
Save abelsaad/4d68fcce938170c66fff9858980ecf3c to your computer and use it in GitHub Desktop.
Get Category
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
// 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