Jump to content

If else if else if else.....????


DSchragg

Recommended Posts

Could someone tell me how to make this work as one statement? Right now it's returning results for every if statement....

 

<!--About-->
         <?php if (is_page(26) || $post->post_parent=="26") { ?>
            <p><?php randomtext('about'); ?></p>
            <?php } else { ?>
            <p><?php randomtext('default'); ?></p>
            <?php } ?>
            
         <!--Get Involved-->
         <?php if (is_page(17) || $post->post_parent=="17") { ?>
            <p><?php randomtext('get-involved'); ?></p>
            <?php } else { ?>
            <p><?php randomtext('default'); ?></p>
            <?php } ?>
            
         <!--Resources-->
         <?php if (is_page(51) || $post->post_parent=="51") { ?>
            <p><?php randomtext('resources'); ?></p>
            <?php } else { ?>
            <p><?php randomtext('default'); ?></p>
            <?php } ?>
            
         <!--Gallery-->
         <?php if (is_page(55) || $post->post_parent=="55") { ?>
            <p><?php randomtext('gallery'); ?></p>
            <?php } else { ?>
            <p><?php randomtext('default'); ?></p>
            <?php } ?>
            
         <!--Whats New-->
         <?php if (is_page(69) || $post->post_parent=="69") { ?>
            <p><?php randomtext('whats-new'); ?></p>
            <?php } else { ?>
            <p><?php randomtext('default'); ?></p>
            <?php } ?>
            
         <!--Testimonials-->
         <?php if (is_page(71) || $post->post_parent=="71") { ?>
            <p><?php randomtext('testimonials'); ?></p>
            <?php } else { ?>
            <p><?php randomtext('default'); ?></p>
            <?php } ?>

 

Thanks in advance for any help.....

Link to comment
https://forums.phpfreaks.com/topic/243036-if-else-if-else-if-else/
Share on other sites

         <?php
         if (is_page(26) || $post->post_parent=="26") {
         $rand_text = "about";
         } elseif (is_page(17) || $post->post_parent=="17") {
         $rand_text = "get-involved";
         } elseif (is_page(51) || $post->post_parent=="51") {
         $rand_text = "resources";
         } elseif (is_page(55) || $post->post_parent=="55") {
         $rand_text = "gallery";
         } elseif (is_page(69) || $post->post_parent=="69") {
         $rand_text = "whats-new";
         } elseif (is_page(71) || $post->post_parent=="71") {
         $rand_text = "testimonials";
         } else {
         $rand_text = "default";
         }
         
         echo "<p>".randomtext($rand_text)."</p>";
         ?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.