Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have this class for my posts:

<?php post_class( 'entry-image' ); ?>

I want to add the category names to get isotope work, i followed this guide http://www.acegoulet.com/2012/03/isotope-and-wordpress-how-i-did-it/ and i used this code to get category names:

$post_cats = get_the_category(); foreach( $post_cats as $category ) { echo $category->slug.' ';}

but this doesn't work. I tried to add a comma between the class and the category:

<?php post_class( 'entry-image', $post_cats = get_the_category(); foreach( $post_cats as $category ) { echo $category->slug.' ';} ); ?>

I checked the firebug but I don't see category name in loops (posts).
Why this doesn't work?

Thank you for help!

share|improve this question

1 Answer 1

up vote 1 down vote accepted

You have to pass the values, not echo them.

So something like this should work:

$post_cats = get_the_category();
$slugs = wp_list_pluck( $post_cats, 'slug' );
post_class( join( ' ', $slugs );
share|improve this answer
    
Thank you so much! –  Fuiba Apr 15 '13 at 19:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.