loop mix my child-category and parent-category
-
Hi Everybody,
i explain the situatio I’m having:
I have a blog, which on the homepage, have display the most recent post.
For each post category, I have set up one specific color and icon by css.
ex: for category pet:
article.category-pets .meta-category a { color: white; float: left; padding: 2px; padding-left: 25px; background: url(https://mywebsite.com/wp-content/uploads/2015/02/pets-30_30.png) no-repeat left; background-size: 15px 15px; background-color: #a2591e; background-position-x: 5px; padding-right: 5px; }
which works perfectly.
The Loop i’m using to display the category name is:
<?php $category = get_the_category(); echo $category[0]->cat_name; ?>
What i would like to achieve is:
Display only the child-category of the post ( If the post is linked to a child category and his parent category) – and if the post is setup to only one parent category – display this parent category.
This loop works not really good, because, If i have my post linked for example:
Parent Category A
Child Category A1and
Parent Category B
Child category B1It is going to mess it up, in my case it display the child-category name ( eg. B1) – but with the icon and background-color of the Parent-Category A.
IT should display only the name of Child-Category A – with background-color and icon of A / not of B.
I can not use a loop to display only child-category or only parent-category because some post ( there is thousands) are only setup to a parent category.
I would really love any helps in that, would be lovely !
Thank you for all your time ??
- The topic ‘loop mix my child-category and parent-category’ is closed to new replies.