尝试了几种方法,但没有一种方法可行,也无法弄清楚还能做些什么。作为团队页面的一部分,我有一个带有4个子字段的转发器字段 - 图像,标题(标题),链接(触发模式)和细节(模态文本内容) - 其中一些应该在单击时打开一个带有额外信息的模态。模态工作正常,但是当我尝试在代码中插入一个计数器以打开每个团队成员的相应子字段时,它会停止工作而不会打开任何内容。
这是代码。非常感谢任何帮助。
<div class="team-block w4 clear" >
<?php
if( have_rows('team_member') ):
$counter = 1;
?>
<ul>
<?php
while( have_rows('team_member') ): the_row();
// vars
$image = get_sub_field('team_member_image');
$title = get_sub_field('team_member_title');
$link = get_sub_field('link_to_details');
$details = get_sub_field('team_member_details');
?>
<li class="team-member-box">
<?php if( $link ): ?>
<a href="<?php echo $link; ?>">
<?php endif; ?>
<img class="team-member-image" src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt'] ?>" />
<?php
echo $title;
if( $link ):
?>
</a>
<?php
endif;
if( $link ):
?>
<div class="remodal team-member-details" data-remodal-id="modal<?php echo $counter;?>">
<button data-remodal-action="close" class="remodal-close"></button>
<h3>Qualifications</h3>
<p><?php echo $details; ?></p>
</div>
<?php endif; ?>
</li>
<?php
$counter++;
endwhile;
?>
</ul>
<?php endif; ?>
</div>
答案 0 :(得分:0)
检查出来:
<a href="#modal1">Modal №1</a>
<a href="#modal2">Modal №2</a>
<a href="#modal3">Modal №3</a>
<div class="remodal team-member-details" data-remodal-id="modal1">
<button data-remodal-action="close" class="remodal-close"></button>
<h3>Qualifications</h3>
<p>yeah</p>
</div>
<div class="remodal team-member-details" data-remodal-id="modal2">
<button data-remodal-action="close" class="remodal-close"></button>
<h3>Qualifications</h3>
<p>yeah 2</p>
</div>
<div class="remodal team-member-details" data-remodal-id="modal3">
<button data-remodal-action="close" class="remodal-close"></button>
<h3>Qualifications</h3>
<p>yeah 3</p>
</div>
这可以按预期工作。当我查看你的代码时,我认为点击图像shoukd会触发模态,对吧?我是这样,试试这个:
<div class="team-block w4 clear" >
<?php if( have_rows('team_member') ): ?>
<?php $counter = 1; ?>
<ul>
<?php while( have_rows('team_member') ): the_row();
// vars
$image = get_sub_field('team_member_image');
$title = get_sub_field('team_member_title');
$link = get_sub_field('link_to_details');
$details = get_sub_field('team_member_details');
?>
<li class="team-member-box">
<a href="modal<?php echo $counter;?>">
<img class="team-member-image" src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt'] ?>" />
<?php echo $title; ?>
</a>
<?php if( $link ): ?>
<div class="remodal team-member-details" data-remodal-id="modal<?php echo $counter;?>">
<button data-remodal-action="close" class="remodal-close"></button>
<h3>Qualifications</h3>
<p><?php echo $details; ?></p>
</div>
<?php endif; ?>
</li>
<?php $counter++; ?>
<?php endwhile; ?>
</ul>
<?php endif; ?>
</div>
我不确定这是否正确(不知道怎么处理$ link var)但是这应该有效。