dongxun8189 2015-10-23 15:24
浏览 66
已采纳

使用WordPress中的高级自定义字段动态地向Bootstrap Modal添加内容

I'm trying to loop through my custom fields created with Advanced Custom Fields and display an image gallery (using a repeater field) in a modal window. The WordPress installation utilizes Bootstrap and I'm trying to change the ID of the modal window based on the order of the post. First post should display #myModal-1, where the second post should output #myModal-2 etc. This should be replicated in the modal window code accordingly.

For some reason the counter is not working and I have no idea why.

See Pastebin below for relevant code.

http://pastebin.com/nYwnMBEJ

  • 写回答

2条回答 默认 最新

  • doume1301 2015-11-12 14:22
    关注

    Your $i++; should be in the endwhile.

    example:

    <div class="sidebar">
      <p><strong>Role:</strong>
        <?php the_field( 'prole') ?>
      </p>
      <!-- Project Role -->
      <p><strong>Project Type:</strong>
        <?php the_field( 'ptype') ?>
      </p>
      <!-- Project Type -->
    
      <?php if(get_field( 'repeater')): ; ?>
    
      <?php $i=0; while(has_sub_field( 'repeater')):; ?>
      <a href="#" data-toggle="modal" data-target="#myModal-<?php echo $i; ?>">toggle goes here</a>
    
      <?php $i++; endwhile; ?>
    
      <?php endif; ?>
    
      <?php if(get_field( 'repeater')):  ; ?>
    
      <?php $i=0; while(has_sub_field( 'repeater')): ; ?>
    
      <!-- Modal -->
      <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 modal-lg">
          <div class="modal-content">
    
            <div class="modal-header">
              <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                <span aria-hidden="true">&times;</span>
              </button>
            </div>
            <!-- /modal-header -->
    
            <div class="row">
              <div class="col-xs-11">
    
                <img src="<?php the_sub_field('gallery'); ?>" />
    
              </div>
              <!-- /col -->
            </div>
            <!-- /row -->
    
          </div>
          <!-- /modal-content -->
        </div>
        <!-- /modal-dialog -->
      </div>
      <!-- /modal -->
    
      <?php $i++; endwhile; ?>
    
      <?php endif; ?>
    
    </div <!-- /sidebar -->
    
    </div>
    <!-- /col -->
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料