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")
    {
    
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器