WordPress ACF转发器PHP get_row_index获取最后一行而不是第一行删除逗号JSON-LD

问题描述

我正在使用WordPress ACF插件并设置一个非常基本的JSON LD Repeater。但是,由于中继器向每个中继器添加了一个逗号,因此我无法验证JSON-LD代码,这使代码无效,因为JSON-LD脚本的最后一个对象一定不能使用公共对象。

这是我正在使用的代码:

  "review": [
  <?php if(have_rows('customer_reviews_repeater')): ?>
  <?php while(have_rows('customer_reviews_repeater')): the_row(); ?>
    {
      "@type": "Review","author": "<?php the_sub_field('customer_name'); ?>","datePublished": "<?php the_sub_field('date_hidden'); ?>","description": "<?php the_sub_field('review_body'); ?>","reviewRating": {
        "@type": "Rating","ratingValue": "<?php the_sub_field('review_value'); ?>"
      }
    },<!-- // This comma should not appear on the last ROW -->
  <?php endwhile; ?>
  <?php endif; ?> 
  ],

中继器工作正常,但我需要摆脱中继器最后一行的最后一个公用。 ACF使用get_row_index(),想知道这是否可以适应我的需要。我已经尝试过<?php if( get_row_index() != 1 ){ echo ',' } ?>了,但这只将逗号输出到第一行,我需要为最后一行而不是第一行适配器该代码!希望有人对PHP或ACF更加了解,可以为我指出正确的方向,或者提供我需要的代码。

这是我的带有get行的代码,但是如前所述,它仅将逗号添加到第一行。除了最后一行,我需要输出到所有行:

  <?php if(have_rows('customer_reviews_repeater')): ?>
  <?php while(have_rows('customer_reviews_repeater')): the_row(); ?>
    {
      "@type": "Review","ratingValue": "<?php the_sub_field('review_value'); ?>"
      }
    }<?php if( get_row_index() != 1 ){ echo ','; } ?>
  <?php endwhile; ?>
  <?php endif; ?>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)