Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

wp_list_pages doesn't acknowledge parent page WordPress

  • SOLVED

I have a theme-provided widget that lists the sub-pages of the current page. It's simply a widget wrapping the wp_list_pages function. I've also used that raw function elsewhere in my templates, and it's worked fine.

It suddenly stopped working. I lost track of what created the problem, so I've had trouble backtracking. As of now, regardless of what page I visit, it presents only the top-tier items. It is as if the parent/child relationships of my pages no longer exist. I've double-checked and the still look fine. Sub-pages are related to their parents via the Page Attributes > Parent dropdown.


<?php if(have_posts()) : while(have_posts()) : the_post(); ?>
<ul>
<?php
wp_list_pages('title_li=&child_of='.$post->ID);
?>
</ul>
<?php endwhile; endif; ?>


The above code always presents the top-level page items, even when it is used on a sub-page.

Any help is appreciated.

Answers (4)

2010-10-06

Keith Pointon answers:

Ok, I'm not sure why that is showing the top level pages, but WordPress has a workaround to show a list of sub-pages on the codex, go here:

[[LINK href="http://codex.wordpress.org/Function_Reference/wp_list_pages#List_subpages_even_if_on_a_subpage"]]List subpages even if on a subpage[[/LINK]]

And it should give you everything you need. I've used this code a few times and it works very well.


<?php
if($post->post_parent) {
$children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");
$titlenamer = get_the_title($post->post_parent);
}

else {
$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
$titlenamer = get_the_title($post->ID);
}
if ($children) { ?>

<h2> <? echo $titlenamer ?> </h2>
<ul>
<?php echo $children; ?>
</ul>

<?php } ?>



2010-10-07

Denzel Chia answers:

Try putting


global $post;


Before wp_list_pages

2010-10-07

Ivaylo Draganov answers:

There's probably something modifying the page query and thus changing the $post variable. But I agree with Oleg Butuzov that there's little we can do without direct debugging. You can of course try the usual practice:

* switch to default theme and test with it
* if the problem persists disable all plugins, start enabling one by one and check each time.
* check your templates for a <em>query_posts</em> anywhere before the call to <em>wp_list_pages()</em>.

2010-10-07

Oleg Butuzov answers:

hm.
Sorry but this issue should be resolved n normal enviropment. one - developer and access to the scripts. Else you will waist much more time.