In my design I show the category of the post in the home page. The problem is when I add more that one category in a post. How can I make so that it will display only one category.
Example: I have 3 categories A, B and C. I add a post in categories A and B. In the home page is displayed ... Post title in category A, B. I want the output to be ... Post title in category A.
For the category I use get_the_category_list
get_the_category() returns an array of all associated categories for the post. To echo out only the first category from the result set try something like:
<?php
$category = get_the_category();
echo $category[0]->cat_name;
?>