如果存在自定义字段,则使用自定义字段的URL回显图像


If custom field exists, echo image with URL of custom field

不起作用,我得到意想不到的T_STRING

 <?php $customfield = get_post_meta($post->ID, 'bannerurl', true);
    if ($customfield == '') { 
        echo '<img src="<?php echo get_post_meta($post->ID, 'bannerurl', true); ?>" alt="text" />'; 
     }
    ?>

尝试如下:

   //if $customfild exist than below will execute else "No Data".
    if (isset($customfield)) { 
    echo '<img src="'.get_post_meta($post->ID, 'bannerurl', true).'" alt="text" />'; }
    else
     echo "No Data";

试试这个

<?php $customfield = get_post_meta($post->ID, 'bannerurl', true);
    if ($customfield == '') { 
        echo '<img src="get_post_meta($post->ID, 'bannerurl', true)" alt="text" />'; 
     }
    ?>
if ($customfield == '') { 
echo '<img src="'.get_post_meta($post->ID, 'bannerurl', true).'" alt="text" />'; }

要检查$customfield是否存在isset()请使用方法 - 您可以在此处阅读有关它的信息。