Bootstrap Modal和AFC Repeater字段

时间:2017-10-15 13:49:19

标签: javascript css twitter-bootstrap bootstrap-modal advanced-custom-fields

我的网站上有一个客户端徽标区域来自高级自定义字段转发器,点击后,我想要一个模态窗口弹出我在转发器字段中包含的其余信息。

每个客户都有徽标,标题,案例研究和推荐。我已经成功地将徽标显示在一个漂亮的网格中,但是我在点击弹出模式时遇到了一些麻烦...

这是我的代码:

    <div style="background-color:#ffffff;width:100%;">
    <div class="container margin-top-20" >

        <div class="row">
            <?php if( get_field('client_logos') ): ?>
            <div style="clear:both;margin-top:20px;">
            </div>
            <h3 class="brand-white" >
                Our Clients
            </h3>
            <ul class="blocks blog-block logo-block">
                <?php if( get_field('client_logos') ): ?>
                <?php while( has_sub_field('client_logos') ):  $i=1; ?>

                  <li>


                    <div class="block-image">
                        <div class="logo-image">
                            <div class="logo-center">
                                <?php $logoblock = get_sub_field('client_logo'); ?>
                                <a href="#myModal<?php echo $i;?>" data-toggle="modal" data-target="#myModal<?php echo $i;?>">
                                  <img src="<?php echo $logoblock['sizes']['medium']; ?>">
                                </a>
                            </div>
                        </div>
                    </div>


                    <div class="modal fade col-md-4" id="myModal<?php echo $i;?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                        <div class="modal-dialog" >
                            <div class="modal-content" style="background-color:
                                <?php the_sub_field('box_color'); ?>">
                                <div class="modal-header">
                                    <!-- Close x --> 
                                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                                    <!-- Logo --> 
                                    <?php the_field('client_logo');?>
                                    <!-- Title --> 
                                    <?php the_field('client_title');?>
                                </div>
                                <div class="modal-body">
                                    <!-- Case Study -->
                                    <?php the_field('client_case_study');?>
                                    <!-- Testimonial -->
                                    <?php the_field('client_testimonial');?>
                                </div>
                            </div>
                        </div>
                    </div>


                  </li>

                <?php $i++; endwhile; ?>
                <?php endif; ?>
            </ul>
            <?php else: ?>
            <?php endif; ?>
        </div>

    </div>
</div>

正如您所看到的,循环最初会检查徽标并显示它,但它应该在点击时显示包含所有字段的模态窗口...当我点击时似乎没有发生任何事情 - 我无法看看有什么不对......

这是徽标条的图片,如果有帮助的话:

documentation

1 个答案:

答案 0 :(得分:2)

在看到实例后我看了你的代码就很容易了。

#myModal'.$i.' - 变量未包装在PHP中,因此不显示计数。

将其更改(以及相应的模态div) <a href="#myModal<?php echo $i;?>" data-toggle="modal" data-target="#myModal<?php echo $i;?>"><img src="<?php echo $logoblock['sizes']['medium']; ?>"></a>

计数的标记看起来不对...试试这个:

<div style="background-color:#ffffff;width:100%;">
<div class="container margin-top-20" >

    <div class="row">
        <?php if( get_field('client_logos') ): ?>
        <div style="clear:both;margin-top:20px;">
        </div>
        <h3 class="brand-white" >
            Our Clients
        </h3>
        <ul class="blocks blog-block logo-block">
            <?php if( get_field('client_logos') ): $i = 1; ?>
            <?php while( has_sub_field('client_logos') ): $i ++;?>

              <li>


                <div class="block-image">
                    <div class="logo-image">
                        <div class="logo-center">
                            <?php $logoblock = get_sub_field('client_logo'); ?>
                            <a href="#myModal<?php echo $i;?>" data-toggle="modal" data-target="#myModal<?php echo $i;?>">
                              <img src="<?php echo $logoblock['sizes']['medium']; ?>">
                            </a>
                        </div>
                    </div>
                </div>


                <div class="modal fade col-md-4" id="myModal<?php echo $i;?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                    <div class="modal-dialog" >
                        <div class="modal-content" style="background-color:
                            <?php the_sub_field('box_color'); ?>">
                            <div class="modal-header">
                                <!-- Close x --> 
                                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                                <!-- Logo --> 
                                <?php the_field('client_logo');?>
                                <!-- Title --> 
                                <?php the_field('client_title');?>
                            </div>
                            <div class="modal-body">
                                <!-- Case Study -->
                                <?php the_field('client_case_study');?>
                                <!-- Testimonial -->
                                <?php the_field('client_testimonial');?>
                            </div>
                        </div>
                    </div>
                </div>


              </li>

            <?php endwhile; ?>
            <?php endif; ?>
        </ul>
        <?php else: ?>
        <?php endif; ?>
    </div>

</div>