PHP if else endif和wordpress';s环

PHP if else endif和wordpress';s环,php,wordpress,Php,Wordpress,我对wordpress中的循环有一个问题,我的网站是一个提要聚合器,基本上我希望我的网站在提要包含图像时显示一个图像,如果提要不包含图像,则显示一个指定的图像。 以下是我实际使用的代码: <?php $enclosure = get_post_meta($post->ID , 'enclosure', $single = true); ?> <?php $image=explode(chr(10),$enclosure); ?> <?

我对wordpress中的循环有一个问题,我的网站是一个提要聚合器,基本上我希望我的网站在提要包含图像时显示一个图像,如果提要不包含图像,则显示一个指定的图像。 以下是我实际使用的代码:

    <?php $enclosure =  get_post_meta($post->ID , 'enclosure', $single = true); ?>
    <?php $image=explode(chr(10),$enclosure); ?>
    <?php if(!is_null($image)) : ?>
    <div class="left">
    <a href="<?php the_permalink() ?>" rel="bookmark" title="Link all'articolo: <?php     the_title_attribute(); ?>"><img src="<?php echo $image[0]; ?>" alt="<?php the_title_attribute(); ?>" style="width:150px; text-align:center;"/></a>
    </div>
    <?php endif; ?>

它工作得很好,但现在我想显示一个“默认”图像,如果提要没有提供,我尝试这样做:

    <?php $enclosure =  get_post_meta($post->ID , 'enclosure', $single = true); ?>
    <?php $image=explode(chr(10),$enclosure); ?>
    <?php if(!is_null($image)) : ?>
    <div class="left">
    <a href="<?php the_permalink() ?>" rel="bookmark" title="Link all'articolo: <?php     the_title_attribute(); ?>"><img src="<?php echo $image[0]; ?>" alt="<?php the_title_attribute(); ?>" style="width:150px; text-align:center;"/></a>
    </div>
    <?php else : ?>
    <div class="left">
    <a href="<?php the_permalink() ?>" rel="bookmark" title="Link all'articolo: <?php     the_title_attribute(); ?>"><img src="PATH TO THE DEFAULT IMAGE" alt="<?php the_title_attribute(); ?>" style="width:150px; text-align:center;"/></a>
    </div>
    <?php endif; ?>

但它不起作用。。。 我错在哪里? 对不起我的英语

谢谢

尝试使用

if($image=="" && $image=="null")
{

}
试一试

而不是

`if(!is_null($image)) :`

使用空函数而不是is_null,仅供参考,您不需要在每一行上打开和关闭php标记……正如@SumitGupta所建议的,使用
!空($image)
而不是
!为空($image)
Hi。如果回答了一个问题,你应该接受答案。你可以在一个php块中放入多个语句,不要为每个语句打开和关闭php块。
`if(!is_null($image)) :`