jonnyh431
Member
Posted 3 years ago #
I want to list the child pages of the parent but don't want to go any further e.g
Parent---->Child
But with the code below I get.
Parent---->Child---->Grandchild---->Great Grandchild etc...
<?php
$children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0');
if ($children) { ?>
<ul>
<?php echo $children; ?>
</ul>
<?php } ?>
Could someone help me out please.
jonnyh431
Member
Posted 3 years ago #
How exactly would I use the depth parameter?
As explained on the link provided by renato...
jonnyh431
Member
Posted 3 years ago #
If I use depth though, it shows all of the pages at that depth but I just want the child pages of the current page.
Try this:
<?php
$children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0&depth=1');
if ($children) { ?>
<ul>
<?php echo $children; ?>
</ul>
<?php } ?>
jonnyh431
Member
Posted 3 years ago #
when I try that it shows all of the child pages but also all of the grandchild pages which I don't want.
jonnyh431
Member
Posted 3 years ago #
would I be able to use exclude= in any way?
if I use this code it shows me only the first level of childs -no grandchilds - I've tested this the last 2minutes ;)
but you can't copy and paste this code because the & get to &...
<?php
$children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0&depth=1');
if ($children) { ?>
<ul>
<?php echo $children; ?>
</ul>
<?php } ?>
jonnyh431
Member
Posted 3 years ago #
what do you mean you can't copy and paste?
jonnyh431
Member
Posted 3 years ago #
oh I see what you mean. It does work but it still lists the grandchild pages.
The forum software changes & to & a m p;, so you can't copy and paste the code.
*cough* pastebin *cough* ... ;)
jonnyh431
Member
Posted 3 years ago #
this is driving me crazy, can anyone please help.
Okay not sure what's driving you nuts but will take the code Monika posted and put it here:
http://wordpress.pastebin.ca/1430169
For further understanding please review:
wp_list_pages() <- this article in particular has example and definitions you may want to undestand!!!!!!!!!!!!!!!!!!!!!!!!!!
Stepping Into Template Tags
Stepping Into Templates
Template Hierarchy
jonnyh431
Member
Posted 3 years ago #
I know how to change the & to & but renato/monika's code doesn't do what I want. It shows all of the pages at that depth even the ones not under the current parent.
What I need is code that I can put into my page template that only shows the 1st level of child pages under the current parent.
That's what the "depth=" parameter is for.
Okay I'm missed what you said there--please paste your complete template code at wordpress.pastebin.ca and report the link back here.
jonnyh431
Member
Posted 3 years ago #
Didn't test anything but right off line 13 in that pastebin is wrong (due to the fact you copied code that the forum goofed up)
That line 13 should be:
$children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0&depth=1');
jonnyh431
Member
Posted 3 years ago #
Thanks alot, that fixed it!