douhulao7642 2015-07-08 11:01
浏览 64
已采纳

PHP与混合了wordpress标签的HTML混合使用输出错误

This question is really specific and for some of you guys maybe really easy to answer. I'm struggling with something for a website for a client already 2 hours. I will try to explain it as good as possible. I made use of custom fields in Wordpress so that the customer can add images to products. I show the images in a lightbox like this (with plugin lightbox plus): <a rel="lightbox[<?php the_field('actietitel'); ?>]" href="<?php the_field('productafbeelding2'); ?>"> </a> . But when there is no "productafbeelding2 for example, HTML will still creat that lightbox but it's value is NULL so it keeps loading. I'm now trying to fix it with an 'if-else-statement' which says:

    <?php 
     if(the_field('actie-afbeelding2') != null) 
   "<a rel='lightbox[" . the_field('actietitel');  "]' href='" . the_field('actie-afbeelding2') .  "'> </a>"
                                                           ?> 

But for some reason it won't work (this is my hundreds attempt so sorry if it is really bad this part of code). Actually, it works but it returns the URL and not in the lightbox. But the first piece of code I showed you actually DOES return the link in a lightbox.

You can see it yourself at: http://www.bgc-testomgeving.nl/jorn/ambachtelijk/

Hope you guys can help me!

PS: i'm SO sorry for my grammar, I suck at it.

  • 写回答

4条回答 默认 最新

  • dongtuan1594 2015-07-08 11:18
    关注

    Use this code

    <?php 
         if(isset(get_field('actie-afbeelding2') && get_field('actie-afbeelding2')!= "") {
       echo "<a rel='lightbox[";
       the_field('actietitel');  
       echo "]' href='";
       the_field('actie-afbeelding2');
       echo "'> </a>";
    }
                                                               ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分