I have this code:
<?php
global $post;
$children = get_pages( array( 'child_of' => $post->ID ) );
if ( is_page() && $post->post_parent > 0 )
{
// Is subpage
// Here I want to get all sibling from the current page
}
else
{
// Is no subpage
if( count( $children ) == 0 )
{
// Has no children
}
else
{
// Has children
echo '<div class="subnav-header">';
echo '<div class="subnav-table">';
echo '<ul>';
foreach($children as $child){ ?>
<li><a href="<?php echo $child->guid; ?>"><?php echo $child->post_title; ?></a></li>
<?php }
echo '</ul>';
echo '</div>';
echo '</div>';
}
}
?>
First, it detects if the current page is a subpage, or normal page. When the page is a subpage, I want to display all the sibling pages of the current page just like I did if the page is no subpage, and has children.
So, in short, what I want to do is this:
- When the current page is a subpage, check if the page has any siblings.
- If the page has sibling, display them in a foreach loop.