admin管理员组文章数量:1316851
I am trying to display a sub-menu with the sub-pages of a parent, if you are on the parent page, and the siblings if you are on one of the child pages, but the problem is that if the page have a featured image is recognized az a parent. this is the code I use:
// 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>';
}
the problem is that I do not get to the second else-if, if the child page have an atachment.
I am trying to display a sub-menu with the sub-pages of a parent, if you are on the parent page, and the siblings if you are on one of the child pages, but the problem is that if the page have a featured image is recognized az a parent. this is the code I use:
// 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>';
}
the problem is that I do not get to the second else-if, if the child page have an atachment.
Share Improve this question asked Nov 6, 2020 at 16:46 Botond VajnaBotond Vajna 4714 silver badges11 bronze badges1 Answer
Reset to default 0You should specify the post_type
for the get_children()
function, which can be one of attachment
, page
, revision
or any
and considered to be any
by default:
$children = get_children( array( 'post_parent' => get_the_ID(), 'post_type' => 'page' ) );
本文标签: phpcheck if page have childrenbut not attachment
版权声明:本文标题:php - check if page have children, but not attachment 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742010696a2412829.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论