• Hello

    I have a simple if/else condition that I just cant seem to get right. I have it half working in that all the pages other than those specified as is_page are displaying correctly ie they call gallery.php and not the image but the pages that are specified as is_page display both the image and gallery.php where they should only be displaying the image. Please help.

    Here is my code:

    <?php
    if (is_page(‘apparel’)) { echo ‘<img src=”https://website/featured/image_apparel.jpg”>&#8217;; }
    if (is_page(‘automotive’)) { echo ‘<img src=”https://website/featured/image_car.jpg”>&#8217;; }
    else include (ABSPATH . ‘/wp-content/plugins/featured-content-gallery/gallery.php’); }
    ?>

    Thanks.

Viewing 6 replies - 1 through 6 (of 6 total)
  • try to use if/elseif/else;

    example using your code:

    if (is_page('apparel')) { echo '<img src="https://website/featured/image_apparel.jpg">'; }
    elseif (is_page('automotive')) { echo '<img src="https://website/featured/image_car.jpg">'; }
    else include (ABSPATH . '/wp-content/plugins/featured-content-gallery/gallery.php'); }

    Try giving this a go…

    <?php if (is_page( 'apparel' )) {
        echo '<img src="https://website/featured/image_car.jpg" />';
    } elseif (is_page( 'automotive' )) {
        echo '<img src="https://website/featured/image_car.jpg" />';
    } else {
        include (ABSPATH . '/wp-content/plugins/featured-content-gallery/gallery.php');
    } ?>

    Sorry alchymyth, forgot to refresh my page after I got back with a cup of coffee. I didn’t see you had already replied. ??

    Thread Starter Daryl Glass

    (@daryl-glass)

    Thank guys for your speedy response, I will give it a try and let you know.

    @theape
    no problem – I do this a lot myself ??

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘PHP If / else condition not working for me’ is closed to new replies.