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

Need help with PHP else if WordPress

  • SOLVED

I've got the following code:



<?php if(get_field('wide_or_small_navigation') == "wide") { ?>

Do something here

<?php } ?>



I want to make it so that it works like this:



<?php if(get_field('wide_or_small_navigation') == "small") { ?>

Do something like <?php the_field('test'); ?>

else if

Do something else like <?php the_field('test'); ?>

else if

<?php } ?>



So basically, if wide is chosen do one thing, if small is chosen do another and if neither is chosen, the final item.

Answers (4)

2016-01-08

Andrea P answers:

something like this?


<?php if( get_field('wide_or_small_navigation') == "small") : ?>

<?php // do something if it's small ?>

<?php elseif ( get_field('wide_or_small_navigation') == "wide" ) : ?>

<?php // do something if it's wide ?>

<?php else : ?>

<?php // do something if it's neither of the two ?>

<?php endif; ?>


Kyler Boudreau comments:

Andrea - worked beautifully! Thank you.

2016-01-08

isp_charlie answers:

<?php if(get_field('wide_or_small_navigation') == "small") { ?>



Do something like <?php the_field('test'); ?>



<?php } elseif( //condition ){ ?>



Do something else like <?php the_field('test'); ?>



<?php } else { ?>

Do something else like <?php the_field('test'); ?>

<?php } ?>

2016-01-08

Navjot Singh answers:

You can go like

<?php if (get_field('wide_or_small_navigation') == "small") { ?>

Do something like <?php the_field('test'); } ?>

<?php elseif (get_field('wide_or_small_navigation') == "wide") { ?>

Do something like <?php the_field('test'); } ?>

<?php else { ?>

Do something

<?php } ?>

2016-01-08

dimadin answers:

Something like this? Or I didn't understand what is a problem.

<?php
$value = get_field('wide_or_small_navigation');
if($value== "wide") { ?>

<?php } elseif ($value == "small") { ?>

<?php } else {?>

<?php } ?>