• Resolved matthewpaul

    (@matthewpaul)


    Basically, I want to write an if statement that says:

    if (page is titled “About” or page is a child of the “About” page)
    // do this
    else
    // do this

    What is the code I need to check if the page is a child of the “About” page? This is what I have so far:

    <?php if (is_page('About')) : ?>
    // do this
    <?php else : ?>
    // do this
    <?php endif ?>

    Help is appreciated.

Viewing 9 replies - 1 through 9 (of 9 total)
  • Derived from example in wp_list_pages() ??

    <?php
      $children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0');
      if ($children) { ?>
        <ul>
        <?php echo $children; ?>
        </ul>
        <?php
      } else {
    // your else stuff
      }
    ?>

    Of course you can replace the $post->ID with some other value if needed…

    Thread Starter matthewpaul

    (@matthewpaul)

    Thanks! I got it working, except if I add child pages to another parent page (other than “About”), it affects them as well.

    Where do I add the page ID or page title of my “About” page so only that page and its children are affected? For example, I replaced $post->ID with the ID # of the “About” page, but received a parse error.

    $children = wp_list_pages('title_li=&child_of=2&echo=0');
    Thread Starter matthewpaul

    (@matthewpaul)

    I replaced:

    <?php
    $children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0');
    if (($children) || ($post->post_parent)) : ?>

    with:

    <?php
    $children = wp_list_pages('title_li=&child_of=11&echo=0');
    if (($children) || ($post->post_parent)) : ?>

    however it is not working. I am sure the ID # is correct. Any suggestions?

    If you use this does it list the pages?

    wp_list_pages('title_li=&child_of=11&echo=1');

    Thread Starter matthewpaul

    (@matthewpaul)

    No, it doesn’t list anything…

    Then there are no children for page id 11.

    Thread Starter matthewpaul

    (@matthewpaul)

    My bad, thought I had the correct ID.

    The only problem is that the if statement still affects all child pages, not just the ones that are children to the page ID I set.

    I found a solution that worked:

    <?php if (is_page('About') || $post->post_parent=="20") : ?>

    Wow, just wanted to thank everyone in this thread. I was able to use the code above to single out all first children pages of specific parent pages:

    <?php if (is_page('About') || $post->post_parent=="20") : ?>

    Thanks everyone! – Ted Goas

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘if child page help’ is closed to new replies.