Forums

if elseif for custom field (3 posts)

  1. hughesmedia
    Member
    Posted 1 year ago #

    Hi, I can't get this to work, someone help please.

    I want to tell it to show the flash when on front page, show banner if the custom field has a banner, and show a generic image if custom field is empty. I am able to get the flash and custom field to show correctly, however, I can't get the generic banner to show up when the custom field is empty. Could someone let me know what it should be?
    Thanks.

    <?php
    	$key="banner";
    if (is_front_page())
    {
    	  echo "<object width='685' height='255'><param name='movie' value='../wp-content/themes/PPS2010/images/perimeterplasticsurgery2.swf' /><param name='quality' value='high' /><embed src='../wp-content/themes/PPS2010/images/perimeterplasticsurgery2.swf' quality='high' pluginspage='http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash' width='685' height='255'></embed>'</object>";
    } elseif ($key)  {
    	  echo get_post_meta($post->ID, $key, true);
    } else {
    	echo "<img src='../wp-content/themes/PPS2010/images/flashholder.jpg' />";
    }
    ?>
  2. mdbitz
    Member
    Posted 1 year ago #

    Hi:

    The issue you have is that $key is always equal to "banner" and so if not on the fornt page it will always resolve to the elseif statement.

    You need to check the return value of get_post_meta. If not empty then echo the meta content.

    <?php
    	$key="banner";
    if (is_front_page())
    {
    	  echo "<object width='685' height='255'><param name='movie' value='../wp-content/themes/PPS2010/images/perimeterplasticsurgery2.swf' /><param name='quality' value='high' /><embed src='../wp-content/themes/PPS2010/images/perimeterplasticsurgery2.swf' quality='high' pluginspage='http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash' width='685' height='255'></embed>'</object>";
    } elseif (get_post_meta($post->ID, $key, true) != "")  {
    	  echo get_post_meta($post->ID, $key, true);
    } else {
    	echo "<img src='../wp-content/themes/PPS2010/images/flashholder.jpg' />";
    }
    ?>
  3. hughesmedia
    Member
    Posted 1 year ago #

    Thank you so much!!!

Topic Closed

This topic has been closed to new replies.

About this Topic