WordPress.org

Ready to get started?Download WordPress

Forums

Add a UL of child pages? (11 posts)

  1. Odenberg
    Member
    Posted 3 years ago #

    Is there a way to show a list of child pages on the parent page and on the childpages, but NOT on any other page?

  2. esmi
    Forum Moderator
    Posted 3 years ago #

  3. Odenberg
    Member
    Posted 3 years ago #

    I have gone through that over and over. But I cant seem to find the right solution.

    I have no problem with listing the childpages. It puting the list on just that specific parent page and its children and not on any other pages that causes me grey hairs.

    I tried by adding 'exclude' to the call for the list. It would be a okey solution if I did´nt have a news section. I would prefer not to have to go in to the code and add a new page-ID to the exclude list, everytime a make a new post.

    Is there any "show only on page-IDno.X and its children"-code I could use?

  4. oturia
    Member
    Posted 3 years ago #

    The solution esmi listed will accomplish that. Please post a link to the page you want it on and we'll see if we can whip up an answer for you.

  5. oturia
    Member
    Posted 3 years ago #

    I haven't heard back, so I'm going to take a guess at what you're trying to accomplish.

    You can take the code you already have in place, based on your other post from yesterday:

    <div id="page-list">
    
          <?php wp_list_pages('child_of=9& exclude=539,540 title_li='); ?> 
    
    </div>

    Then wrap it in a conditional statement that checks to see if you are currently on that page or one of it's children. An example that may work would be:

    <?php is_page(array(42,'Murmelins-Parent-page','Murmelin's Parent Page')){
    ; ?>

    Then insert your list pages query, and close out the conditional statement with:

    `<?php } ?>

    I haven't tested this code, but in theory it accomplishes what I understand your goal to be. If this doesn't work, post back a link to your site and some more details and we'll see if we can help.

  6. Odenberg
    Member
    Posted 3 years ago #

    Thanks a lot for tring to help me, Oturia!

    Had to leave the computer for a couple of ours, children to feed and put to bed ;-)

    Any way, now Im back.

    Is this what you suggest me to do?

      <?php is_page(array(42,'webshop')){; ?>
      <?php wp_list_pages('child_of=9& title_li='); ?><?php } ?>

    Here is my webpage:
    bastardforlag.se/webshop

    Thanks agai for taking time to help me. I really appriciate it!

  7. oturia
    Member
    Posted 3 years ago #

    Yes, though you may want to add the child pages to the array. You don't have to list the same page twice, just list the array of page ids or names you want it to show on.

    <?php if ( is_page(array('webshop', 'Kassa', 'Varukorg', 'etc'))){; ?>
    <?php wp_list_pages('child_of=9&title_li='); ?>
    <?php } ?>

    That should do the trick. let me know if it doesn't.

  8. Odenberg
    Member
    Posted 3 years ago #

    The thing is that there are also other pages that will be added as child-child-pages.

    Is there a way to show the list at the parent page and all of its descendents?

  9. oturia
    Member
    Posted 3 years ago #

    How about this:

    [Code moderated as per the Forum Rules. Please use the pastebin]

  10. Odenberg
    Member
    Posted 3 years ago #

    Oh, the code have been removed. Could you please sent it again?

  11. oturia
    Member
    Posted 3 years ago #

    The code was way too long, apparently. I should've known better.

    Try this link. I added the code there to the pastebin.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.