dongtang4019 2013-07-26 07:36
浏览 85

PHP if if else endif和wordpress的循环

I've a problem with the loop in wordpress, my website is a feed aggregator and basically I want my website to display an image if the feed contains an image or a specified image if it doesn't. here's the code I actually use:

    <?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; ?>

It works very well but now I want to show a "default" image if the feed doesn't provide one, I tried in this way:

    <?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; ?>

But it doesn't work... Where am I wrong? Sorry for my english!

Thanks!

  • 写回答

2条回答

  • dongyiba8082 2013-07-26 07:39
    关注

    try to use

    if($image=="" && $image=="null")
    {
    
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!