简体   繁体   English

每个转发器字段的唯一ID(高级自定义字段)

[英]Unique ID for each repeater field (advanced custom fields)

I'm creating wordpress page that has a program schedule. 我正在创建具有节目时间表的wordpress页面。 Im using advanced custom fields to allow us to easily fill parts the day and removing things etc. However each block has its own collapsible description with an href. 我使用高级自定义字段,以便我们可以轻松地填充当天的部件并移除等等。但是每个块都有自己的可折叠描述和href。 When I'm creating the repeater it however keeps the id of that collapsible part the same and it doesn't work cause it would always open 'description 1' 当我创建转发器时,它保持该可折叠部分的id相同并且它不起作用因为它将始终打开'描述1'

My question: how can i apply a unique id (ie progam1, program2 etc) to each repeater loop. 我的问题:如何将唯一的id(即progam1,program2等)应用于每个转发器循环。 Ive tried it with $counter as seen in the code below, but I'm not sure how to correctly apply it. 我已经用$ counter尝试了它,如下面的代码所示,但我不确定如何正确应用它。

<?php 
while ( have_rows('day_1') ) : the_row();

    $progtime             = get_sub_field('prog_time');
    $progtitle            = get_sub_field('prog_title');
    $progimage           = get_sub_field('prog_image');
    $progsubspeaker     = get_sub_field('prog_sub_speaker');
    $progsubdescription = get_sub_field('prog_sub_description');
    $progsubduration    = get_sub_field('prog_sub_duration');
    $progsublocation    = get_sub_field('prog_sub_location');
    $progsubabouttitle  = get_sub_field('prog_sub_abouttitle');
    $progsubabout       = get_sub_field('prog_sub_about');
    $progsubabouturl    = get_sub_field('prog_sub_abouturl');
    $counter = 1;

    ?>
    <!-- PROGRAM 1-->
    <div class="panel panel-default">

        <!-- Program Heading -->
        <div class="panel-heading" role="tab" id="heading1">

            <div class="row">
                <div class="col-lg-1 col-md-1 col-sm-1">
                    <p class="date"><?php echo $progtime; ?></p>
                </div>

                <div class="col-lg-11 col-md-11 col-sm-11">

                    <h4 class="panel-title">
                        <a data-toggle="collapse" data-parent="#accordion" href="#Program<?php echo $counter; ?>" aria-expanded="true" aria-controls="Program1">
                            <?php echo $progtitle; ?>
                        </a>
                    </h4>
                </div>
            </div>

        </div>

        <div id="Program<?php echo $counter; ?>" class="panel-collapse collapse" role="tabpanel" aria-labelledby="heading1">
            <!-- Program Content -->
            <div class="panel-body">
                <div class="row">
                    <div class="col-lg-2 col-md-2 col-sm-2">
                        <img class="img-responsive img-circle" src="<?php echo $progimage; ?>" alt="">
                    </div>

                    <div class="col-lg-7 col-md-7 col-sm-10">
                        <p class="speaker-name uppercase"><?php echo $progsubspeaker; ?></p>
                            <h4><?php echo $progtitle; ?></h4>
                                <p><?php echo $progsubdescription; ?></p>

                                <p><i class="fa fa-lg fa-clock-o"></i><span class="small"><?php echo $progsubduration; ?></span></p>
                                <p><i class="fa fa-lg fa-map-marker"></i> <span class="small"><?php echo $progsublocation; ?></span></p>
                            </div>

                            <div class="col-lg-3 col-md-3 col-sm-10">
                                <h5><?php echo $progsubabouttitle; ?></h5>
                                <p class="small"><?php echo $progsubabout; ?></p>
                                <span class="about-speaker"><i class="fa fa-lg fa-globe"></i> <a class="small" href="#"><?php echo  $progsubabouturl; ?></a></span>
                            </div>

                        </div>
                    </div>

                </div>

            </div>
            <?php $counter++; ?>
        <?php endwhile; ?> 

Got it. 得到它了。 I used this source on stackoverflow as the solution. 在stackoverflow上使用此源作为解决方案。

I had to define $counter before the loop and add $counter++ in the loop, so each time the loop loops it would add +1. 我必须在循环之前定义$ counter并在循环中添加$ counter ++,所以每次循环循环时它都会加+1。

Your problem is that $counter is defined as 1 within the loop, so everytime it runs it's setting it back to equal 1. 你的问题是$ counter在循环中定义为1,所以每次运行它都会将它设置回等于1。

Move $counter = 1 above the while statement and this should work for you! 在while语句上方移动$ counter = 1,这应该适合你!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 高级自定义字段 - 循环遍历转发器子字段并显示每个转发器字段的特定子字段属性 - Advanced Custom Fields - looping through repeater subfields and displaying a specific subfield attribute of each repeater field 两列重复器字段高级自定义字段 - Two Column Repeater Field Advanced Custom Fields 高级自定义字段(ACF)-遍历转发器签出字段并输出每个值的单个实例 - Advanced Custom Fields (ACF) - loop through repeater checkout field and output single instance of each value 为每个转发器字段创建唯一的ID - Create unique id for each repeater field 更新中继器字段高级自定义字段中的库字段 - update gallery field in repeater field advanced custom fields 使用WooCommerce自定义产品选项卡中的“高级自定义字段中继器”字段 - Using Advanced custom fields Repeater field in WooCommerce custom product Tab 从PHP和Timber / Twig中的高级自定义字段中排序转发器字段 - Sorting a repeater field from Advanced Custom Fields in PHP and Timber/Twig PSA:高级自定义字段 the_repeater_field 迭代太频繁 - PSA: advanced custom fields the_repeater_field iterates too often 高级自定义字段WordPress中继器字段按日期排序 - Advanced Custom Fields Wordpress Repeater Field Order By Date 使用高级自定义字段插件和转发器字段在Wordpress中制作幻灯片 - Making a Slideshow in Wordpress using the Advanced Custom fields plugin and the repeater field
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM