WordPress.org

Ready to get started?Download WordPress

Forums

How do I say: if parent = _____ then _____ (4 posts)

  1. celticks
    Member
    Posted 2 years ago #

    How can I code this?
    "if parent = _____ then _____"

    Thanks.

  2. theotherlebowski
    Member
    Posted 2 years ago #

    you may need to explain what you're actually trying to do as that's exceptionally vague...

  3. celticks
    Member
    Posted 2 years ago #

    I am trying to have it so if a page is a child of a certain page to display something there.

    something along the lines of:
    if (parent=Testimonials)
    get_template_part( 'loop', 'testimonials' );
    }

  4. converting2wp
    Member
    Posted 2 years ago #

    Assuming the page id of Testimonials is 123, then use

    if ( 123 == $post->post_parent ) ...

    See http://codex.wordpress.org/Function_Reference/get_post for other properties of the current post that you can reference in the same way.

    Note 1: You can use a plugin to display the page id - e.g. Reveal IDs or simply hover over the edit link in the All Pages screen and the ID will show up in the edit URL.

    Note 2: If you want to use the page slug (e.g. 'testimonials') instead of the ID, see the example http://codex.wordpress.org/get_posts#Get_a_post_by_its_slug but change "'post_type' => 'post'," to "'post_type' => 'page',".

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.