【问题标题】:Display specific taxonomy of CPT then display children of that taxonomy显示 CPT 的特定分类,然后显示该分类的子级
【发布时间】:2018-06-16 13:41:21
【问题描述】:

我正在尝试输出我使用自定义帖子类型创建的自定义分类法列表。这是我想要实现的截图:

ConstructionIndustrialOffice 是父分类(类别),以下是它们的子分类。

除了图标,我只想显示一个特定的主要分类,然后在其下方显示该类别的子级。

但是在两个不同的部分,所以我可以设置不同的父级和子级。

分类术语是:job_listing_category - 所以我假设我可以显示 job_listing_category('Construction'),然后在同一个 div 中显示:job_listing_category('Construction', 'children')

我知道这不是正确的语法,但我正在学习。

这似乎是一件简单的事情,但我似乎无法找到一种方法来做到这一点。

我有下面的代码,它显示了所有类别的列表...所以我需要更改它以仅显示其中一个类别的子项...

    <?php
$terms = get_terms( 'job_listing_category', 'orderby=count&hide_empty=0' );
$count = count($terms);
if ( $count > 0 ){
 echo "<ul>";
 foreach ( $terms as $term ) {
   echo "<li>" . $term->name . "</li>";

 }
 echo "</ul>";
}
?>

显然,还有很多缺失...我非常感谢任何帮助。感谢大家花时间阅读:)

【问题讨论】:

    标签: php wordpress custom-post-type custom-taxonomy


    【解决方案1】:

    好的,我设法通过使用以下代码来完成这项工作:

    <?php
    $terms = get_terms( 'job_listing_category', 'parent=59' );
    $count = count($terms);
    if ( $count > 0 ){
     echo "<ul>";
     foreach ( $terms as $term ) {
       echo "<li>" . $term->name . "</li>";
    
     }
     echo "</ul>";
    }
    ?>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多