我自定义了帖子类型和分类法,在我的页面模板上,我想在css类中呈现分类法名称。有人知道如何渲染吗?
这就是我目前所拥有的
<?php
$args = array( \'post_type\' => \'portfolio\', \'posts_per_page\' => 10 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
$terms = get_the_terms( get_the_ID(), \'portfolio\' );
//debugging array
echo \'<pre>\';
print_r($terms);
echo \'</pre>\';
echo "<a href=\'" .get_the_permalink() . "\'><figure class=\'". $terms->name ."\'>";
the_post_thumbnail();
echo "</figure></a>";
endwhile;
?>
结果是:
Array
(
[200] => stdClass Object
(
[term_id] => 200
[name] => Plugins
[slug] => plugins
[term_group] => 0
[term_taxonomy_id] => 200
[taxonomy] => portfolio
[description] =>
[parent] => 0
[count] => 1
[object_id] => 1776
[filter] => raw
)
)
我试着这样称呼它:
$terms->name;
但我在wp中得到了以下信息:
Notice: Trying to get property of non-object in....