Wordpress echo post子类别

问题描述 投票:-2回答:1

所以我回应了一系列帖子作为标题。每个帖子属于一个特定的类别和子类别,以便使用这些标题从该标题所属的子类别中加载ajax的所有帖子。我需要回显每个标题的子类别的id。请帮忙! :)

wordpress
1个回答
0
投票
   foreach((get_the_category($post->ID)) as $childcat) {
      echo $childcat->cat_name . '</a>';
  }

if you have some key for subcategories,  You can classify categories as below.
foreach((get_the_category()) as $childcat) {
  if (cat_is_ancestor_of(10, $childcat)) {
   echo $childcat->cat_name . '</a>';
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.