当插入计数器时,ACF中继器字段未打开模式


ACF repeater field not opening modal when inserting counter

尝试了几种方法,但都不起作用,也不知道还能做什么。作为团队页面的一部分,我有一个中继器字段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>

看看这个:

<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>

按预期工作。当我看你的代码时,我假设点击图像应该触发模态,对吧?如果这样,试试这个:

<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),但这应该工作