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条)

报告相同问题?