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

sidebar menu code WordPress

  • SOLVED

last week I asked a question and got a great answer - but now that we are entering content there seems to be an issue I'm hoping someone can fix.

The code is to display children of any page that has children and siblings if a page doesn't have chldren. works beautifully until the third level down.

<?php
if (is_page()) {
if($post->post_parent){
// will display the subpages of this top level page
$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
if (!$children) {
$children = wp_list_pages('title_li=&child_of='.$post->post_parent.'&echo=0&depth=1');
}
} else {
$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0&depth=1");
}
?>
<?php if ($children) { ?>
<ul class="subpages">
<?php echo $children; ?>
</ul>
<?php }
}
?>


It may be difficult to see on this page because of the way the menu is nested but the list of names starting with Charles are actually children pages of "Consulting Team" on [[LINK href="http://www.brandmagik.com/gt/?page_id=35"]]this page[[/LINK]]

What do I have to change in the code to get it to drill down all the way?

Answers (2)

2010-11-15

idt answers:

Hi borzoid, I still don't understand what you are trying to do here. Do you want to show the names of the consulting team while on still this page: http://www.brandmagik.com/gt/?page_id=212 ?

If so, then just remove &depth=1 from this line of codes:
$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0&depth=1"); and
$children = wp_list_pages('title_li=&child_of='.$post->post_parent.'&echo=0&depth=1');

idt


Connie Taylor comments:

The names of the consulting team are children and shouldn't be showing on that page.

the menu works here:

<blockquote>top page - child page - child page</blockquote>

but doesn't work down to this level

<blockquote>top page - child page - child page - child page</blockquote>

I hope that make it clearer


idt comments:

Ah so the list names are not suppose to be showing while on this page for example?
http://www.brandmagik.com/gt/?page_id=237


Connie Taylor comments:

Names should show on this page

http://www.brandmagik.com/gt/?page_id=237


but not on this page (it's parent)

http://www.brandmagik.com/gt/?page_id=35


Connie Taylor comments:

Names should show on this page

http://www.brandmagik.com/gt/?page_id=237


but not on this page (it's parent)

http://www.brandmagik.com/gt/?page_id=235


idt comments:

Try changing this: $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
to
$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0&depth=1");


idt comments:

The names that showed up on this page:http://www.brandmagik.com/gt/?page_id=235, they are sub-pages of which page?


Connie Taylor comments:

That fixed it, Thank you.

They were actually grandchildren pages which was why it was so weird. but your code change fixed the issue.

2010-11-15

Jermaine Oppong answers:

I do not really understand what youre asking for? I think you are asking for all page ancestors to be listed without and depth restrictions, i.e. drill all the way down. Try this


<?php

if (is_page()) {

if($post->post_parent){

// will display the subpages of this top level page

$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");

if (!$children) {

$children = wp_list_pages('title_li=&child_of='.$post->post_parent.'&echo=0');

}

} else {

$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");

}

?>

<?php if ($children) { ?>

<ul class="subpages">

<?php echo $children; ?>

</ul>

<?php }

}

?>



Ive removed <strong>depth</strong> so there will be no depth restrictions.