check if page have children, but not attachment

Question

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.

0
Botond Vajna 3 months 0 Answers 7 views 0

Leave an answer