我试图显示一个子菜单,如果您在父页面上,则显示父页面的子页面,如果您在其中一个子页面上,则显示同级页面,但问题是,如果页面具有特征图像,则会被识别为父页面。这是我使用的代码:
// check if page have children
$children = get_children( get_the_ID() );
if ( ! empty($children)) {
echo \'<ul class="submenu">\';
wp_list_pages(array(
\'child_of\' => $post->ID,
\'title_li\' => 0,
\'item_spacing\' => \'discard\'
// \'exclude\' => $post->ID
));
echo \'</ul>\';
} else if ($post->post_parent){
echo \'<ul class="submenu">\';
// get a back link to the parent
echo \'<li class = "bold parentbut"><a href ="\' . get_permalink($post->post_parent) . \'">\' . get_the_title($post->post_parent) . \'</a></li>\';
wp_list_pages(array(
\'child_of\' => $post->post_parent,
\'title_li\' => 0,
\'item_spacing\' => \'discard\'
// \'exclude\' => $post->ID
));
echo \'</ul>\';
} else {
echo \'<div class="dunga-albastra"></div>\';
}
问题是,如果子页面有一个atachment,我无法访问第二个else if。