My post category structure is 3-level deep:
I want to show all posts from "Milk products" and add appropriate category slug as class, for example - a post with name "Cacao Chocolate" is inside Chocolate category and I want it to have "Chocolate" slug.
With the following code all my posts added to category "Milk products" have the slug "Milk" - doesn't matter if they are also in category Milk, chocolate or cheese.
<?php query_posts('category__in=39'); while ( have_posts() ) : the_post(); echo '<li class="mix '. $category->slug .'" data-filter="'. $category->slug .'">'. get_the_content() .'</li>'; endwhile; // Reset Query wp_reset_query(); ?>
Any idea how to get the the last category slug of the post?