http://wordpress.org/support/topic/38264
seems to be almost there. If….I….could….just….connect…the…dots…
I’m so close! Some one, please, help a bruva out.
<ul class="pages">
<?php
$current_page = $post->ID;
$parent = 1;
while($parent) {
$page_query = $wpdb->get_row("SELECT post_name, post_parent FROM $wpdb->posts WHERE ID = '$current_page'");
$parent = $current_page = $page_query->post_parent;
if(!$parent)
$parent_name = $page_query->post_name;
}
?>
<?php global $id; // the page id
$kids = get_pages("child_of=$id");
if (count($kids) > 0) {wp_list_pages('child_of=' . $id . '&title_li=&sort_column=menu_order');}
elseif (count($kids) == 0) {wp_list_pages('child_of=' . $parent . '&title_li=&sort_column=menu_order');}
?>
</ul>
I’ve just been hacking and ctrl+Zing and searching and copying and hacking and ctrl+Zing and sea…. It’s close! It correctly displays the children of pages with children. on the pages with 0 children, it displays ALL pages and their children. I just want it to display the children of it’s parent.
I tried every variable from the upper area (I’m seriously just guessing and trying again… that’s a little closer, guess some more…)
please help! thankyouthankyouthankyou.
Will
Hi, I don’t know if you figured it out, but I managed to solve it with the this plugin :
http://brams.dk/public/wp/tbr_article_family.zip
Here you can check the parent of a page. (You can see an example here: http://www.billnighy.info/filmography/
The child pages are shown when choosing filmography, and when you click on one of the children, the siblings are displayed.
Hope this helps you out.
Is it possible to list sibling pages, without having to create multiple sidebars? (you have to do this with tbr_article_family.php)
<?php /* Creates a menu for pages beneath the level of the current page */
if (is_page() and ($notfound != '1')) {
$current_page = $post->ID;
while($current_page) {
$page_query = $wpdb->get_row("SELECT ID, post_title, post_status, post_parent FROM $wpdb->posts WHERE ID = '$current_page'");
$current_page = $page_query->post_parent;
}
$parent_id = $page_query->ID;
$parent_title = $page_query->post_title;
if ($wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_parent = '$parent_id' AND post_status != 'attachment'")) { ?>
<div class="sb-pagemenu"><h2><?php echo $parent_title; ?> Subpages</h2>
<ul>
<?php wp_list_pages('sort_column=menu_order&title_li=&child_of='. $parent_id); ?>
</ul>
<?php if ($parent_id != $post->ID) { ?>
<a href="<?php echo get_permalink($parent_id); ?>">Back to <?php echo $parent_title; ?></a>
<?php } ?>
</div>
<?php } } ?>
Wow thanks Dylan, this is perfecto 🙂
One question – if I’m on a parent page, this page is not shown in the list. How could I force it to be shown?
For example, if you have ‘About’ with 2 pages below it called ‘People’ and ‘History’ – the menu on ‘About’ lists only these sub pages, and not ‘About’. When you go into ‘People’ or ‘History’, ‘About’ then shows up in the list…
Ok I worked this out – this is a tweaked version of the above code, which will always include the parent page at the top of the list (even if you are on that page)
<?php /* Creates a menu for pages beneath the level of the current page */
if (is_page() and ($notfound != '1')) {
$current_page = $post->ID;
while($current_page) {
$page_query = $wpdb->get_row("SELECT ID, post_title, post_status, post_parent FROM $wpdb->posts WHERE ID = '$current_page'");
$current_page = $page_query->post_parent;
}
$parent_id = $page_query->ID;
$parent_title = $page_query->post_title;
if ($wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_parent = '$parent_id' AND post_status != 'attachment'")) { ?>
<ul>
<?php ?>
<li><a href="<?php echo get_permalink($parent_id); ?>"><?php echo $parent_title; ?></a></li>
<?php ?>
<?php wp_list_pages('sort_column=menu_order&title_li=&child_of='. $parent_id); ?>
</ul>
<?php } } ?>