WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Child Page Conditional (4 posts)

  1. joshrodgers
    Member
    Posted 1 year ago #

    I have a parent page and some child pages - example: my parent page is "people" and my child pages are "billy", "tom", and "phil". I am looking for a conditional statement that I can write so if we're on page "tom" and only on page "tom" do "something", if not do "something else".

    I thought this would work: http://pastebin.com/DSMhPi0f

    But this code displays "something" on all child pages, not just on child page "tom".

    Any ideas?
    Thanks,
    Josh

  2. Andrew
    Forum Moderator
    Posted 1 year ago #

    Check Codex' function reference http://codex.wordpress.org/Function_Reference/
    Where did you get is_child from?

  3. joshrodgers
    Member
    Posted 1 year ago #

    Andrew,

    Sorry about that...this is in my functions file: http://pastebin.com/SKyi1hWh.

    Thanks,
    Josh

  4. joshrodgers
    Member
    Posted 1 year ago #

    I don't know what I was thinking earlier...I guess somehow I was thinking that is_page wouldn't work for my child page, but I was over-thinking...this is my final code:

    <?php if (is_page("tom")) {
    echo "do something";
    } else {
    echo "something else";
    } ?>

    I know, I know it's so simple, but it works - guess I was just having a brain fart.

    Thanks,
    Josh

Topic Closed

This topic has been closed to new replies.

About this Topic