【问题标题】:How to auto increase the number in ACF PRO LOOP如何在 ACF PRO LOOP 中自动增加数字
【发布时间】:2020-01-07 15:13:59
【问题描述】:

我想自动增加每个“id”中的数字,我使用 ACF PRO 并选择了“Repeater”类型。 我在下面尝试了这些代码,但它不起作用

<?php
$counter = -1;
if( have_rows('thongtin') ):
    while ( have_rows('thongtin') ) : the_row(); $counter++ ?>
        <?php get_template_part('templates/listmatcat'); ?>
    <?php endwhile;
else :
endif;
?> 

// The code in templates/listmatcat.php file
// I want to auto increase the number with #pr_file 

<tr>
    <td class="col col1">
        <p class="name r"><?php the_sub_field('masomatcat') ?></p>
        <a href="#pr_file<?php echo $counter; ?>" class="open_profile" rel="pr_dt"><img src="<?php the_sub_field('anhmatcattrai'); ?>" alt="" /></a>
        <div class="clearAll"></div>
        <a href="#pr_file<?php echo $counter; ?>" class="open_profile"><span class="active_s"></span></a>
    </td>
    <td class="col_center"></td>
    <td class="col col2" style="text-align:left">
        <div class="info"><img src="<?php the_sub_field('anhmatcatphai'); ?>" alt="" /></div>
    </td>
</tr>```

【问题讨论】:

    标签: wordpress advanced-custom-fields repeater acfpro


    【解决方案1】:

    这看起来像是 get_template_part() 函数的限制。根据this article,你会想做这样的事情:

    include(locate_template('[YOUR-FILE-NAME].php'));
    

    或者,如果您实际上不需要为循环的内容使用外部文件(如果它只被这个文件使用过),只需删除 get_template_part() 并将内容直接放入循环中。

    【讨论】:

      猜你喜欢
      • 2011-06-21
      • 2018-09-15
      • 2015-11-04
      • 2020-09-04
      • 2019-09-14
      • 1970-01-01
      • 2021-11-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多