【问题标题】:Display Wordpress child and Parent terms显示 Wordpress 子项和父项
【发布时间】:2020-12-10 16:00:43
【问题描述】:

我有一个“位置”分类法,我希望在存档页面上显示帖子位置术语。每个帖子都有一个子术语,因此在父美国下方打勾“纽约”。

在我希望显示的前端 - 美国纽约

所以打勾的子项,然后是父项。

目前我只有

<?php echo get_the_term_list( $post->ID, 'location'); ?> 

它只显示勾选的术语,但我希望它也能拉入父术语。

【问题讨论】:

标签: php wordpress taxonomy-terms


【解决方案1】:

为了得到当前postterms的父terms

$terms = wp_get_post_terms($post->ID, 'location');

foreach ($terms as $term) {
 echo get_term_link( $term ); // get the child term url
 echo get_term_link( $term->parent ); // get parent term url
 $parent = get_term($term->parent, 'location');
 echo $parent->name;
}

【讨论】:

  • 如何添加指向此的链接?
  • 您可以使用get_term_link()函数。我更新了我的答案
猜你喜欢
  • 1970-01-01
  • 2019-07-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-10-15
  • 1970-01-01
  • 2013-03-14
  • 2023-03-26
相关资源
最近更新 更多