Support » Fixing WordPress » How do I say: if parent = _____ then _____
4 years, 8 months ago
How can I code this?
“if parent = _____ then _____”
you may need to explain what you’re actually trying to do as that’s exceptionally vague…
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:
get_template_part( ‘loop’, ‘testimonials’ );
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’,”.