我试图从名为“城市”的层次分类法中只获取顶级术语。它在某种程度上工作得很好,因为它输出了额外的元素。。。
$cities = get_terms( \'city\' , array(
\'parent\' => 0,
\'orderby\' => \'name\',
\'order\' => \'ASC\',
\'hide_empty\' => true
));
foreach ($cities as $city) { ?>
<li><a href="<?php echo get_term_link( $city, \'city\' ); ?>" class="button radius"><?php echo $city->name; ?></a><li>
<?php } ?>
</ul>
其中只返回2个城市(每个城市都有几个子术语),返回的HTML如下所示:
<li> ... correct data about term 1 </li>
<li>
</li>
<li> ... correct data about term 2 </li>
<li>
</li>
</ul>