drake900918 2015-05-21 15:43
浏览 53
已采纳

如果Field为空,则显示某些div

I have the following code but it is not working.

Basically I want it so if the field movie_title_2 is empty I want it to add the , but if it is not empty to show just . I am using wordpress and Advanced Custom Fields plugin. Thanks!

<div class="homepage-opacity">
    <div class="movie-container">
    <?php if (get_field('movie_title_2') && get_field('movie_title_2') != "") { ?>

        <div class="movie-area alone">
            <div class="movie-poster">          
            <?php  if ( get_field('movie_image_poster') ) : ?>
                <img src="<?php the_field('movie_image_poster'); ?>" alt="<?php the_field('movie_image_poster'); ?>}">
            <?php endif; ?>
            </div>
            <div class="movie-info">
            <?php
            if(get_field('movie_title'))
            {
                echo '<h1 class="movie-title">' . get_field('movie_title') . '</h1>';
            }
            ?>  
            <?php
            if(get_field('movie_dates_&_times'))
            {
                echo '<p class="movie-times">' . get_field('movie_dates_&_times') . '</p>';
            }
            ?>  
            <?php  if ( get_field('trailer_link') ) : ?>
                <a class="movie-trailer" href="<?php the_field('trailer_link'); ?>" target="_blank">View the Trailer</a>
            <?php endif; ?>

            </div>
        </div>

    <?php } ?>
    <?php if (get_field('movie_title_2') && get_field('movie_title_2') == "") { ?>

        <div class="movie-area">
            <div class="movie-poster">          
            <?php  if ( get_field('movie_image_poster') ) : ?>
                <img src="<?php the_field('movie_image_poster'); ?>" alt="<?php the_field('movie_image_poster'); ?>}">
            <?php endif; ?>
            </div>
            <div class="movie-info">
            <?php
            if(get_field('movie_title'))
            {
                echo '<h1 class="movie-title">' . get_field('movie_title') . '</h1>';
            }
            ?>  
            <?php
            if(get_field('movie_dates_&_times'))
            {
                echo '<p class="movie-times">' . get_field('movie_dates_&_times') . '</p>';
            }
            ?>  
            <?php  if ( get_field('trailer_link') ) : ?>
                <a class="movie-trailer" href="<?php the_field('trailer_link'); ?>" target="_blank">View the Trailer</a>
            <?php endif; ?>

            </div>
        </div>
        <div class="movie-area">
            <div class="movie-poster">          
            <?php  if ( get_field('movie_image_poster_2') ) : ?>
                <img src="<?php the_field('movie_image_poster_2'); ?>" alt="<?php the_field('movie_image_poster_2'); ?>}">
            <?php endif; ?>
            </div>
            <div class="movie-info">
            <?php
            if(get_field('movie_title_2'))
            {
                echo '<h1 class="movie-title">' . get_field('movie_title_2') . '</h1>';
            }
            ?>  
            <?php
            if(get_field('movie_dates_&_times_2'))
            {
                echo '<p class="movie-times">' . get_field('movie_dates_&_times_2') . '</p>';
            }
            ?>  
            <?php  if ( get_field('trailer_link_2') ) : ?>
                <a class="movie-trailer" href="<?php the_field('trailer_link_2'); ?>" target="_blank">View the Trailer</a>
            <?php endif; ?>

            </div>
        </div>
        <?php } ?>
    </div>
</div>
  • 写回答

1条回答 默认 最新

  • donglun1020 2015-05-21 15:49
    关注

    try:

      <?php 
        $variable = get_field('movie_title_2');
    
        if ($variable) { ?>
    
    <h1>Add html just like you would normally do</h1>
    
    <?php } else { ?>  
    
    <h1>Add different html here when the variable is empty</h1>
    
    
        <?php } ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答