Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php PostWordPress的打印类别_Php_Wordpress - Fatal编程技术网

Php PostWordPress的打印类别

Php PostWordPress的打印类别,php,wordpress,Php,Wordpress,我已经尝试了所有与codex提供的打印类别相关的功能,但我还没有找到任何适合我的方法 我试图打印类别slug,以便将其放入类中 我想用类proyect打印div中实际帖子的类别,这样我就可以用它过滤同位素了 <!-- feature posts --> <div id="container"> <?php $the_query = new WP_Query('showposts=5&orderby=p

我已经尝试了所有与codex提供的打印类别相关的功能,但我还没有找到任何适合我的方法

我试图打印类别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 -->    

发件人:


您应该能够使用:

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

这将是一个和这篇文章相关的类别数组。然后你可以循环浏览它们,做任何你需要的事情。

你试过这个吗?哇,非常感谢!这完全奏效了,我坚持了3个小时,并尝试了一系列解决方案,我猜没有找到正确的方法。上帝保佑你!出于某种原因,这与所有帖子中的同一类别相呼应。它不起作用
$cats = wp_get_post_categories($post->ID);