【问题标题】:If statement looping twiceif语句循环两次
【发布时间】:2015-10-02 19:10:06
【问题描述】:

我正在尝试获取它,因此如果设置了该字段,则显示上半部分,否则显示一个位置。它在某种程度上有效,事实上它显示了空,但它显示了两次,我似乎无法弄清楚为什么

<?php if( have_rows('attach_files_multiple') ): while ( have_rows('attach_files_multiple') ) : the_row(); ?>  

                        <?php if( get_row_layout() == 'neck' ) : ?>
                        <div class="media">
                            <div class="media-left media-middle">
                            <!-- Image Start -->
                                <?php $image = get_sub_field('preview_prop_neck');
                                if( !empty($image) ): ?>
                                    <img class="media-object" width="100px" src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
                                <?php endif; ?>
                            <!-- Image End -->
                            </div>

                            <div class="media-body">
                                <?php $file = get_sub_field('prop_file_neck'); ?>
                                <h4 class="media-heading">
                                    Neck Piece 
                                    <a href="<?php echo $file['url']; ?>" class="pull-right btn btn-primary"><i class="fa fa-download"></i> Download</a>
                                </h4>
                            </div>
                        </div>
                        <?php elseif ( !empty(get_row_layout('neck')) ) : ?>
                            <div class="overlay"><h3>Helmet - No File Found</h3></div>
                            <div class="media">
                            <div class="media-left media-middle">
                            <!-- Image Start -->
                                <img class="media-object" width="100px" src="<?php bloginfo('template_directory'); ?>/images/pdo.png">
                            <!-- Image End -->
                            </div>
                            <div class="media-body">
                                <h4 class="media-heading">
                                    Neck Piece 
                                    <a href="#" class="pull-right btn btn-primary"><i class="fa fa-download"></i> Download</a>
                                </h4>
                            </div>
                        </div>
                        <?php endif; ?>
                        <?php endwhile; ?> <!-- End while ( have_rows( ) -->
                        <?php endif; ?> <!-- End if( have_rows ) ?> -->

【问题讨论】:

    标签: wordpress if-statement advanced-custom-fields


    【解决方案1】:
                        <?php if( get_row_layout() == 'neck' ) : ?>
    

    这里你说的是“如果颈行布局存在,输出下面的布局”。

                    <?php elseif ( !empty(get_row_layout('neck')) ) : ?>
    

    这里你基本上是在说“如果颈行布局不为空,则输出下面的布局”。所以它输出了两次,因为我假设你有一个脖子。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-05-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多