打印Wordpress的类别

时间:2014-01-03 20:49:10

标签: php wordpress

我已经尝试了与编码提供的打印类别相关的所有功能,但我找不到任何适用于我的方法。

我试图打印类别slug,把它放在一个类中。

我想用类proyect打印div中实际帖子的类别,然后我可以用它来过滤同位素。

<!-- 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 -->    

2 个答案:

答案 0 :(得分:1)

来自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 . ' ';} ?>">

答案 1 :(得分:0)

你应该可以使用:

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

这是与此帖相关的类别数组。然后你可以遍历它们并做你需要的任何事情。

相关问题