Forums

PHP If / else condition not working for me (7 posts)

  1. Daryl Glass
    Member
    Posted 1 year ago #

    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="http://website/featured/image_apparel.jpg">'; }
    if (is_page('automotive')) { echo '<img src="http://website/featured/image_car.jpg">'; }
    else include (ABSPATH . '/wp-content/plugins/featured-content-gallery/gallery.php'); }
    ?>

    Thanks.

  2. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    try to use if/elseif/else;

    example using your code:

    if (is_page('apparel')) { echo '<img src="http://website/featured/image_apparel.jpg">'; }
    elseif (is_page('automotive')) { echo '<img src="http://website/featured/image_car.jpg">'; }
    else include (ABSPATH . '/wp-content/plugins/featured-content-gallery/gallery.php'); }
  3. theApe
    Member
    Posted 1 year ago #

    Try giving this a go...

    <?php if (is_page( 'apparel' )) {
        echo '<img src="http://website/featured/image_car.jpg" />';
    } elseif (is_page( 'automotive' )) {
        echo '<img src="http://website/featured/image_car.jpg" />';
    } else {
        include (ABSPATH . '/wp-content/plugins/featured-content-gallery/gallery.php');
    } ?>
  4. theApe
    Member
    Posted 1 year ago #

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

  5. theApe
    Member
    Posted 1 year ago #

  6. Daryl Glass
    Member
    Posted 1 year ago #

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

  7. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    @theApe
    no problem - I do this a lot myself :-)

Topic Closed

This topic has been closed to new replies.

About this Topic