Forums

[resolved] wp_list_pages help me!!! (21 posts)

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

    Could someone help me out please.

  2. renato_s
    Member
    Posted 3 years ago #

  3. jonnyh431
    Member
    Posted 3 years ago #

    How exactly would I use the depth parameter?

  4. Mark / t31os
    Moderator
    Posted 3 years ago #

    As explained on the link provided by renato...

  5. 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.

  6. renato_s
    Member
    Posted 3 years ago #

    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 } ?>
  7. 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.

  8. jonnyh431
    Member
    Posted 3 years ago #

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

  9. Monika
    Member
    Posted 3 years ago #

    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 } ?>
  10. jonnyh431
    Member
    Posted 3 years ago #

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

  11. jonnyh431
    Member
    Posted 3 years ago #

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

  12. asechrest
    Member
    Posted 3 years ago #

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

  13. Mark / t31os
    Moderator
    Posted 3 years ago #

    *cough* pastebin *cough* ... ;)

  14. jonnyh431
    Member
    Posted 3 years ago #

    this is driving me crazy, can anyone please help.

  15. MichaelH
    Volunteer
    Posted 3 years ago #

    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

  16. jonnyh431
    Member
    Posted 3 years ago #

    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.

  17. MichaelH
    Volunteer
    Posted 3 years ago #

    That's what the "depth=" parameter is for.

  18. MichaelH
    Volunteer
    Posted 3 years ago #

    Okay I'm missed what you said there--please paste your complete template code at wordpress.pastebin.ca and report the link back here.

  19. jonnyh431
    Member
    Posted 3 years ago #

  20. MichaelH
    Volunteer
    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');

  21. jonnyh431
    Member
    Posted 3 years ago #

    Thanks alot, that fixed it!

Topic Closed

This topic has been closed to new replies.

About this Topic