如果页面有子页面,则显示子导航


If page has children show sub nav

我正在创建一个wordpress主题,我希望只在当前页面有子页面时显示子导航,我使用下面的代码,它工作得很好,但没有if语句,这意味着它在某些页面上显示一个空菜单。

<?php global $id;
        wp_list_pages("title_li=&child_of=$id&show_date=modified&date_format=$date_format");
?>

尝试:-

$kids = get_pages("child_of=$id");
if (count($kids) > 0) { wp_list_pages(...); }