I want to add a ribbon on my posts on the front page, which shows the posts category.
I can add it as text like this (I use the Imbalance theme by WPShower):
<?php imbalance2_posted_in(); ?>
But how can I just write the Category Name
, without markup so I can use it in classes and such?
Thank you in advance.
You can get the category of every post with get_the_category(). Below is shown how to get the category of the current post.
EDIT
You can use
post_class()
to generate a few class names including one for each category.If you want to do it manually, you can get information on the categories using
get_the_category()
and put the class names together yourself.