我有一个列表,您可以在其中显示类别,但我希望您不要显示子类别,只显示类别
$term_id = get_categories();
if (function_exists(\'get_wp_term_image\'))
{
$meta_image = get_wp_term_image($term_id);
//It will give category/term image url
}
$categories = get_categories();
foreach($categories as $category) {
?>
<article>
<div class="poster">
<a href="<?php echo get_category_link($category->term_id); ?>">
<?php echo \'<img src="\'.get_wp_term_image($category->term_id).\'">\' ?>
</div>
<div class="orbit_starts">
<h2><?php echo $category->name ?></h2></a>
</div>
</article>
如何排除所有子类别?
非常感谢。
最合适的回答,由SO网友:Parthavi Patel 整理而成
$args = array(
\'orderby\' => \'name\',
\'order\' => \'ASC\',
\'parent\' => 0
);
$categories = get_categories($args);
愿这对你有帮助。参考此
link