php - 显示 Wordpress 子项和父项
问题描述
我有一个“位置”分类法,我希望在存档页面上显示帖子位置术语。每个帖子都有一个子术语,因此在父级 US 下标记为“纽约”。
在我希望展示的前端 - 美国纽约
所以打勾的子项,然后是父项。
目前我只有
<?php echo get_the_term_list( $post->ID, 'location'); ?>
它只显示了勾选的术语,但我希望它也能引入父术语。
解决方案
为了得到当前职位条款的父条款
$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;
}
推荐阅读
- flutter - Scaffold 不是类型 '(BuildContext, ChangeNotifier, Widget) => Widget' 的子类型
- python - Python re.sub 问题
- c# - ASP.NET Core 2.2 MVC:包装响应
- python - 不同数据框的列之间的相关性
- python - 如何结合颜色检测器和 SSD 检测器来识别人?
- sqlite - 如何解决 django 和 sqlite 的兼容性问题?
- assembly - REP INSW 是做什么的?
- testing - Flutter 中的小部件测试失败,但将 Flutter 升级到 1.9.1 后,每个设备中的屏幕都可以正确渲染
- javascript - 在 Phonegap 中使用 jQuery 的问题
- laravel - laravel 中的慢查询