在Wordpress中,我为一个名为"People“的CPT创建了一个名为”城市“的分类法。我希望在single.php-文件的模板中显示为某个人选择的所有分类标记。
只显示所选元素的代码是什么?
我在Sing-People.php中使用了以下代码:
<?php
$taxonomy = 'cities';
$terms = get_terms($taxonomy);
if ( $terms && !is_wp_error( $terms ) ) :
?>
<ul>
<?php foreach ( $terms as $term ) { ?>
<li><a href="<?php echo wp_get_post_terms($term -> slug, $taxonomy); ?>"><?php echo $term -> name; ?></a></li>
<?php
} ?>
</ul>
<?php endif; ?> 我只想要选择的分类标签没有链接。
发布于 2014-03-31 18:08:21
我知道您希望显示为单个帖子选择的分类法的所有术语。
您需要像这样使用函数wp:
$taxonomy = 'cities';
$post_terms = wp_get_post_terms( $post->ID, $taxonomy, array( "fields" => "names" ) );
foreach ( $post_terms as $term ) {
echo $term;
}这将打印当前职位相关的所有城市的名称。现在,您必须调整此代码以适应您的页面,如果您不想要链接,只需不使用<a>标记.
发布于 2022-09-26 13:50:41
$wrap = 'hello';
$terms = wp_get_post_terms(get_the_ID( ), $wrap, array("fields"=>"names"));
foreach ( $terms as $term ) {
echo $term;
}
在hello的位置上,您取了分类法名,它肯定会运行。
https://stackoverflow.com/questions/22767378
复制相似问题