Carlos E. Guillen
Carlos E. Guillen

Reputation: 35

Print category of post Wordpress

I have try all the functions related to print categories that the codex provide, but i havent found any way that works for me.

Im trying to print the categories slug for put it inside a class.

I want to print the category of the actual post in div with the class proyect, so then i can use it to filter with isotope.

<!-- feature posts -->
             <div id="container">
                <?php $the_query = new WP_Query('showposts=5&orderby=post_date&order=DESC'); ?> 
                <?php while ($the_query->have_posts()) : $the_query->the_post();
                $id = get_the_ID(); ?>                    
                <div class="proyect <?php wp_get_post_categories($id); ?>">                         
                    <div class="view view-tenth"> 
                       <a style="display:block;" href="<?php the_permalink(); ?>">
                        <article> <?php if ( function_exists("has_post_thumbnail") && has_post_thumbnail() ) { the_post_thumbnail('', array("class" => "")); } ?></article> 
                        </a>
                        <div class="mask">                               
                          <h2><?php echo substr(strip_tags(get_the_title()),0,35); ?></h2></a>
                          <p class="fecha-post"><?php the_time('F j, Y'); ?></p> 
                          <?php echo substr(strip_tags(get_the_content()),0,100); ?>
                          <a class="info" href="<?php  the_permalink(); ?>">Ver más...</a>
                        </div>
                    </div>     
                 </div>
                <?php endwhile;?>  
             </div>
            <!-- #feature post -->    

Upvotes: 2

Views: 3130

Answers (2)

cstef
cstef

Reputation: 74

You should be able to use:

$cats = wp_get_post_categories($post->ID);

This will be an array of the categories associated with this post. Then you can loop through them and do whatever you need.

Upvotes: 1

Martin Majer
Martin Majer

Reputation: 3352

From http://wordpress.org/support/topic/getting-category-slug-from-posts-in-the-loop:

<li class="<?php foreach(get_the_category() as $category) { echo $category->slug . ' ';} ?>">

Upvotes: 2

Related Questions