List a child’s sibling pages in WordPress

I’m build a website for a hotel and in my sidebar file I have a PHP script to print out the list of child pages. The structure is as follows:

So, essentially I want to display the child (ones in the brackets) pages in the sidebar when a user is on the parent page (Restaurant or Rooms) or a child page.

However, my script doesn’t appear to work and doesn’t display the list of pages.

//SET UP FAMILY
    $children = get_pages('child_of='.$post->ID);
    $parent = $post->post_parent;
    $siblings = get_pages('child_of='.$parent);

    if(count($children) != 0 ) {
        $args = array(
            'depth' => 1,
            'title_li' => null,
            'sort_column' => 'menu_order',
            'child_of' => $post->ID
        );
    }

    else if($parent != 0) {
        $args = array(
            'depth' => 1,
            'title_li' => null,
            'sort_column' => 'menu_order',
            'exclude' => $post->ID,
            'child_of' => $parent
        );
    }

    if(count($siblings) > 1 && !is_null($args)) {
        echo "<ul class='pages'>";
        echo "<h2>Browse</h2>";
        wp_list_pages($args);
        echo "</ul>";
    }

I don’t mind if the current page is shown in the menu either.

Related posts