2013-10-28 39 views
-1

不行的回波图像,我得到得到意想不到的T_STRING如果自定义字段存在,与自定义字段的URL

<?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" />'; 
    } 
    ?> 
+2

记住:SO是_not调试工具_ –

+0

@AlmaDoMundo你假的 - '特定的编程problems'也意味着 – TN888

+0

@AlmaDoMundo请仔细阅读[简介】(http://stackoverflow.com/about)页面不要”无所谓我正在使用它作为一个 – TN888

回答

1

尝试象下面这样:

//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"; 
+0

这是工作,但我如何使它不返回自定义字段不存在? – user2188643

+0

不起作用 - 它只是返回一个图像与ALT文本 – user2188643

+0

if()条件之前,你可以像print_r($ customfield)一样,看看有什么值来。 –

0

试试这个

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

检查$customfield是否存在使用isset()方法 - 你可以阅读它here