0

我正在使用 Bootstrap 选项卡在 ACF 转发器字段中显示包含员工资料和照片的网格,当单击配置文件时,会弹出引导模式,其中在转发器子字段中填写了信息。

一切正常,但是当您单击不同的配置文件时,相同的配置文件信息在模态中,而不是不同的配置文件信息。

这是我的代码

    <div class="tab-content" id="myTabContent">

        <div class="tab-pane fade show active" id="team" role="tabpanel" aria-labelledby="team-tab">
        <div class="row justify-content-md-between">

<?php 
if( have_rows('team_profile_boxes') ):
    $i = 1;

    // loop through the rows of data
    while ( have_rows('team_profile_boxes') ) : the_row(); ?>

                    <div id="profile-box">
                        <div class="profile-image-box">
                            <div class="profile-image" style="background-image: url('<?php echo the_sub_field('profile_image'); ?>');"></div>
                            <div class="profile-image-hover" style="background-image: url('<?php echo the_sub_field('second_profile_image'); ?>');"></div>
                        </div>
                    <div class="profile-details">
                            <a data-toggle="modal" href="#exampleModal">
                                <h4>
                                    <span><?php the_sub_field('division_title'); ?></span>
                                    <br>
                                    <?php the_sub_field('profile_name'); ?> <br>
                                    <span><?php the_sub_field('job_title'); ?></span>
                                </h4>
                            </a>
                    </div>

                </div>
                <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
                    <div class="modal-dialog modal-dialog-centered" role="document">
                        <div class="modal-content">
                        <div class="modal-body">
                            <?php the_sub_field('profile_information'); ?>
                        </div>
                        </div>
                        </div>
                    </div>

<?php  $i++;

    endwhile;

else :

    // no rows found

endif;
?>
</div>
</div>

我已经查看了这个例子,但它似乎并不适用: ACF Repeater + Modal

4

3 回答 3

0

我设法使用上述理念解决了它,但使用了以下代码:

<div class="tab-content" id="myTabContent">
        <div class="tab-pane fade show active" id="team" role="tabpanel" aria-labelledby="team-tab">
        <div class="row justify-content-md-between">
<?php 
if( have_rows('team_profile_boxes') ):
    $i = 1;
    // loop through the rows of data
    while ( have_rows('team_profile_boxes') ) : the_row(); ?>
                    <div id="profile-box">
                        <div class="profile-image-box">
                            <div class="profile-image" style="background-image: url('<?php echo the_sub_field('profile_image'); ?>');"></div>
                            <div class="profile-image-hover" style="background-image: url('<?php echo the_sub_field('second_profile_image'); ?>');"></div>
                        </div>
                    <div class="profile-details">
                            <a data-toggle="modal" href="<?php echo '#exampleModal' . $i ?>">
                                <h4>
                                    <span><?php the_sub_field('division_title'); ?></span>
                                    <br>
                                    <?php the_sub_field('profile_name'); ?> <br>
                                    <span><?php the_sub_field('job_title'); ?></span>
                                </h4>
                            </a>
                    </div>
                </div>
                <div class="modal fade" id="<?php echo 'exampleModal' . $i ?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
                    <div class="modal-dialog modal-dialog-centered" role="document">
                        <div class="modal-content">
                        <div class="modal-body">
                            <?php the_sub_field('profile_information'); ?>
                        </div>
                        </div>
                        </div>
                    </div>
<?php  $i++;
    endwhile;
else :
    // no rows found
endif;
?>
</div>
</div>
于 2019-12-11T15:15:33.427 回答
0

你还没有打印$i,试试这个代码......

<div class="tab-content" id="myTabContent">
    <div class="tab-pane fade show active" id="team" role="tabpanel" aria-labelledby="team-tab">
        <div class="row justify-content-md-between">

            <?php 
            if( have_rows('team_profile_boxes') ):
                $i = 1;

                // loop through the rows of data
                while ( have_rows('team_profile_boxes') ) : the_row(); ?>

                    <div id="profile-box-<?php echo $i; ?>">

                        <?php //your code ?>

                    </div>

                    <div class="modal fade" id="profile-box-<?php echo $i; ?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">

                        <?php //your code ?>

                    </div>

                <?php  $i++;

                endwhile;

            else :

            // no rows found

            endif; ?>
        </div>
    </div>
</div>
于 2019-12-11T09:24:23.257 回答
0

您可以使用名为get_row_index()的 acf 内置函数为所有行设置索引。它从 1 开始,一直到行数的末尾。

<div class="tab-content" id="myTabContent">
<div class="tab-pane fade show active" id="team" role="tabpanel" aria-labelledby="team-tab">
    <div class="row justify-content-md-between">
    <?php if( have_rows('team_profile_boxes') ):
    // loop through the rows of data
    while ( have_rows('team_profile_boxes') ) : the_row(); $i = get_row_index();?>
        <div id="profile-box">
            <div class="profile-image-box">
                <div class="profile-image" style="background-image: url('<?php echo the_sub_field('profile_image'); ?>');"></div>
                <div class="profile-image-hover" style="background-image: url('<?php echo the_sub_field('second_profile_image'); ?>');"></div>
            </div>
            <div class="profile-details">
                <a data-toggle="modal" href="#exampleModal-<?php echo $i;?>">
                    <h4>
                        <span><?php the_sub_field('division_title'); ?></span>
                        <br>
                        <?php the_sub_field('profile_name'); ?> <br>
                        <span><?php the_sub_field('job_title'); ?></span>
                    </h4>
                </a>
            </div>
        </div>
        <div class="modal fade" id="exampleModal-<?php echo $i;?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
            <div class="modal-dialog modal-dialog-centered" role="document">
                <div class="modal-content">
                    <div class="modal-body">
                        <?php the_sub_field('profile_information'); ?>
                    </div>
                </div>
            </div>
        </div>
    <?php endwhile; endif; ?>
    </div>
</div>

于 2019-12-11T09:38:50.647 回答