使用 WordPress 中的高级自定义字段将内容动态添加到 Bootstrap 模态
Adding content to Bootstrap Modal dynamically with Advanced Custom Fields in WordPress
我正在尝试遍历使用高级自定义字段创建的自定义字段,并在模式 window 中显示图片库(使用转发器字段)。 WordPress 安装使用 Bootstrap,我正在尝试根据 post 的顺序更改模态 window 的 ID。第一个 post 应该显示 #myModal-1,第二个 post 应该输出 #myModal-2 等。这应该相应地复制到模态 window 代码中。
出于某种原因,计数器不工作,我不知道为什么。
相关代码见下面的 Pastebin。
你的$i++;
应该在最后。
示例:
<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">×</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 -->
今天才发现这个,我知道的晚了,但我想我会分享我的代码。
我正在尝试遍历使用高级自定义字段创建的自定义字段,并在模式 window 中显示图片库(使用转发器字段)。 WordPress 安装使用 Bootstrap,我正在尝试根据 post 的顺序更改模态 window 的 ID。第一个 post 应该显示 #myModal-1,第二个 post 应该输出 #myModal-2 等。这应该相应地复制到模态 window 代码中。
出于某种原因,计数器不工作,我不知道为什么。
相关代码见下面的 Pastebin。
你的$i++;
应该在最后。
示例:
<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">×</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 -->
今天才发现这个,我知道的晚了,但我想我会分享我的代码。