dsg41888 2018-06-16 14:11
浏览 23
已采纳

向孩子展示自定义分类术语

I have the WP Jb manager plugin which I believe is just a custom post type for jobs. I have enabled categories created some categories.

I need to just show the children of each category instead of the whole list of categories.

I have the following code:

<?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>";
}
?>

Which outputs a list of all categories (parent and children) as so:

  • Office
  • Warehouse
  • Manufacturing
  • Industrial
  • Construction
  • Building Services Engineers

The parent categories are the bold ones: Office, Industrial and Construction. I want to take one of them and display the children of that category only.

For example: get_category('industrial', 'children_of') (I know that's not the correct syntax), so it would result in showing the children only of the industrial category:

  • Warehouse
  • Manufacturing

I can't seem to find a way to do this - Could anyone help?

  • 写回答

2条回答 默认 最新

  • dongxi7722 2018-06-16 19:58
    关注

    I managed to do this by using the following code:

    <?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>";
    }
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 关于#html5#的问题:H5页面用户手机返回的时候跳转到指定页面例如(语言-javascript)
  • ¥15 无法使用此凭据登录,因为你的域不可用,如何解决?(标签-Windows)
  • ¥15 yolov9的训练时间
  • ¥15 二叉树遍历没有报错但无法正常运行
  • ¥15 在linux系统下vscode运行robocup3d上场球员报错
  • ¥15 Python语言实验
  • ¥15 SAP HANA SQL 增加合计行
  • ¥20 用C#语言解决一个英文打字练习器,有偿
  • ¥15 srs-sip外部服务 webrtc支持H265格式
  • ¥15 在使用abaqus软件中,继承到assembly里的surfaces怎么使用python批量调动