Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Help with if statement WordPress

  • SOLVED

Hi, wondering if someone can help me with an if statement, I have the below code, but its not exactly what i'm after.

<?php if (is_page(35) || $post->post_parent=="35") { ?>
<div class="pagetitlefood"><?php the_title(); ?></div>
<?php } else { ?>
<p>Oranges</p>
<?php } ?>


What i'm after is:

If page is a child of parent page ID 35, then show: <div class="pagetitlefood"><?php the_title(); ?></div>

If page is a child of parent page ID 36, then show: <div class="pagetitleshopping"><?php the_title(); ?></div>

If page is a child of parent page ID 37, then show: <div class="pagetitleevents"><?php the_title(); ?></div>

If is not a child of any of those then show: <div class="pagetitle"><?php the_title(); ?></div>


Hope that makes sense?
Thanks

Answers (2)

2013-04-04

Arnav Joy answers:

try this

<?php

wp_reset_query();
global $post;
if ( $post->post_parent == 35 ) { ?>
<div class="pagetitlefood"><?php the_title(); ?></div>
<?php } else if ( $post->post_parent == 36 ) { ?>
<div class="pagetitleshopping"><?php the_title(); ?></div>
<?php } else if ( $post->post_parent == 37 ) { ?>
<div class="pagetitleevents"><?php the_title(); ?></div>
<?php } else { ?>
<div class="pagetitle"><?php the_title(); ?></div>
<?php } ?>

2013-04-04

Sébastien | French WordpressDesigner answers:


<?php

if ((is_page(35)) OR ($post->post_parent == 35 )) { ?>
<div class="pagetitlefood"><?php the_title(); ?></div>
<?php } else if ((is_page(36)) OR ($post->post_parent == 36 )) { ?>
<div class="pagetitleshopping"><?php the_title(); ?></div>
<?php } else if ((is_page(37)) OR ($post->post_parent == 37 )) { ?>
<div class="pagetitleevents"><?php the_title(); ?></div>
<?php } else { ?>
<div class="pagetitle"><?php the_title(); ?></div>
<?php } ?>