Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.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 Wordpress:仅显示选定的分类标记_Php_Wordpress_Custom Post Type_Taxonomy - Fatal编程技术网

Php Wordpress:仅显示选定的分类标记

Php Wordpress:仅显示选定的分类标记,php,wordpress,custom-post-type,taxonomy,Php,Wordpress,Custom Post Type,Taxonomy,在Wordpress中,我为一个名为“人”的CPT创建了一个名为“城市”的分类法。我想在single.php-file的模板中显示为个人选择的所有分类法标记 仅显示选定元素的代码是什么 我在single-people.php中使用以下代码: <?php $taxonomy = 'cities'; $terms = get_terms($taxonomy); if ( $terms && !is_wp_error( $terms ) ) : ?> <ul&

在Wordpress中,我为一个名为“人”的CPT创建了一个名为“城市”的分类法。我想在single.php-file的模板中显示为个人选择的所有分类法标记

仅显示选定元素的代码是什么

我在single-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; ?>     


我只想要所选的分类法标签,不带链接。

我知道您想要在一篇文章中显示所选分类法的所有术语

您需要像这样使用函数:

$taxonomy = 'cities';
$post_terms = wp_get_post_terms( $post->ID, $taxonomy, array( "fields" => "names" ) );

foreach ( $post_terms as $term ) {
    echo $term; 
}

这将打印与当前帖子相关的所有城市的名称。现在,您必须使此代码适应您的页面,如果您不需要链接,请不要使用
标记…

除了链接之外,分类名称有什么问题?