Reputation: 5
I have a page structure like this:
Food
Music
When on a child page, I want to a menu that shows the siblings, including the current page. For example, if I am on the 'Fruit' page I want to see: Cheese Fruit Meat Sweets
'Fruit' should not have a link because it is the current page.
I've tried this, but it doesn't include the current page:
<?php
wp_list_pages(array(
'child_of' => $post->post_parent,
'exclude' => $post->ID,
'depth' => 1
));
?>
Upvotes: 0
Views: 1347
Reputation: 722
Your current code have exclude argument, just remove 'exclude' => $post->ID
,so you can see your current page too...
<?php
wp_list_pages(array(
'child_of' => $post->post_parent,
'depth' => 1
));
?>
and to make unclickeble please use below style
<style type="text/css">
.current_page_item a{
pointer-events: none;
cursor: default;
color: #000;
}
</style>
So final code is
<style type="text/css">
.current_page_item a{
pointer-events: none;
cursor: default;
color: #000;
}
</style>
<?php
wp_list_pages(array(
'child_of' => $post->post_parent,
'depth' => 1
));
?>
Upvotes: 1
Reputation: 6650
Here is the logic you need to do. First get the post parent ID:
$post_parent_id = wp_get_post_parent_id( $post_ID );
Then get the children of the parent page :
$my_wp_query = new WP_Query();
$all_wp_pages = $my_wp_query->query(array('post_type' => 'page', 'posts_per_page' => '-1' , 'post__in' => array($post_parent_id)));
$children = get_page_children( $post_parent_id, $all_wp_pages );
echo '<pre>' . print_r( $children, true ) . '</pre>';
Upvotes: 0