wordpress - Wordpress - 在单页上显示类别
问题描述
我使用 ACF 创建自定义帖子类型。对于这种自定义类型,我有两种不同的分类法:
- 项目类型
- 房屋类型
在房屋类型中,我有 4 个不同的类别:
- 所有类型
- 房子
- 公寓
- 建造
每个帖子都需要“所有类型”和另一个(例如:所有类型,房屋)
我想显示主要类别:房屋而不显示:所有类型我如何隐藏“所有类型”?
我的代码:
<div class="detailfiche">
<?php
global $post;
$terms = wp_get_post_terms($post->ID, 'housetype');
if ($terms) {
$output = array();
foreach ($terms as $term) {
$output[] = '<span><a href="' .get_term_link( $term->slug, 'housetype') .'">' .$term->name .'</a></span>';
}
echo join( ' ', $output );
};
?>
</div>
解决方案
试试这个
<?php
global $post;
$terms = wp_get_post_terms($post->ID, 'housetype');
if ($terms)
{
$output = array();
foreach ($terms as $term)
{
if ($term->term_id != 222)
{
$output[] = '<span><a href="' . get_term_link($term->slug, 'housetype') . '">' . $term->name . '</a></span>';
}
}
echo join(' ', $output);
};
?>
将此行中的 222 更改为您的分类 ID 以排除
$term->term_id != 222
推荐阅读
- django - 如何使用 django/postgres 制作嵌套的 jsonb 模型?
- bash - Shell - 在特殊字符之间打印文本
- python - Python shutil.move() 函数
- flutter - 在行 FLUTTER 中添加列表图块后,列表视图消失
- c# - void OnCollisionEnter() 是如何工作的?(统一,c#)
- wpf - 通过为控件名称构建一个字符串,在后面的代码中引用一个窗口控件
- reactjs - 通过 PUT 方法(节点)将字符串数组发送到正文中的特定字段
- reactjs - React Native, passing function with argument from child to parent
- haskell - 当我尝试使用 ghci 加载此 Haskell 代码时,为什么会出现错误?
- c - 如何使用 *x 显示 Hello World