• Resolved jonnyh431

    (@jonnyh431)


    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=&amp;child_of='.$post->ID.'&amp;echo=0');
      if ($children) { ?>
      <ul>
      <?php echo $children; ?>
      </ul>
      <?php } ?>

    Could someone help me out please.

Viewing 15 replies - 1 through 15 (of 20 total)
  • renato_s

    (@renato_s)

    Try the “depth” parameter:
    http://codex.ww.wp.xz.cn/wp_list_pages#Parameters

    Thread Starter jonnyh431

    (@jonnyh431)

    How exactly would I use the depth parameter?

    As explained on the link provided by renato…

    Thread Starter jonnyh431

    (@jonnyh431)

    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.

    renato_s

    (@renato_s)

    Try this:

    <?php
      $children = wp_list_pages('title_li=&amp;child_of='.$post->ID.'&amp;echo=0&amp;depth=1');
      if ($children) { ?>
      <ul>
      <?php echo $children; ?>
      </ul>
      <?php } ?>
    Thread Starter jonnyh431

    (@jonnyh431)

    when I try that it shows all of the child pages but also all of the grandchild pages which I don’t want.

    Thread Starter jonnyh431

    (@jonnyh431)

    would I be able to use exclude= in any way?

    Monika

    (@monika)

    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 &amp…

    <?php
      $children = wp_list_pages('title_li=&amp;child_of='.$post->ID.'&amp;echo=0&amp;depth=1');
      if ($children) { ?>
      <ul>
      <?php echo $children; ?>
      </ul>
      <?php } ?>
    Thread Starter jonnyh431

    (@jonnyh431)

    what do you mean you can’t copy and paste?

    Thread Starter jonnyh431

    (@jonnyh431)

    oh I see what you mean. It does work but it still lists the grandchild pages.

    asechrest

    (@asechrest)

    The forum software changes & to & a m p;, so you can’t copy and paste the code.

    *cough* pastebin *cough* … 😉

    Thread Starter jonnyh431

    (@jonnyh431)

    this is driving me crazy, can anyone please help.

    MichaelH

    (@michaelh)

    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

    Thread Starter jonnyh431

    (@jonnyh431)

    I know how to change the &amp 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.

Viewing 15 replies - 1 through 15 (of 20 total)

The topic ‘wp_list_pages help me!!!’ is closed to new replies.