有一个循环:
<?php if ( have_rows( 'fifth-section' ) ) : ?>
<?php while ( have_rows( 'fifth-section' ) ) : the_row(); ?>
<?php if ( get_sub_field( 'display' ) == 1 ) { ?>
"offers": {
"@type": "AggregateOffer",
"offers": [
<?php if( have_rows('plans') ): ?>
<?php
$loop_counter = 0;
while( have_rows('plans') ): the_row();
if($loop_counter%4 == 0){
if($loop_counter > 0){
?>
<?php } ?>
<?php }
$subtitle = get_sub_field('subtitle');
?>
{
"@type": "Offer",
"name": "<?php echo $subtitle; ?>",
"url": "<?php echo get_permalink(); ?>"
},
<?php
$loop_counter++;
endwhile;
?>
<?php endif; ?>
<?php } else { } ?>
<?php endwhile; ?>
<?php endif; ?>
]
}
}
哪个输出模式标记的块
"offers": {
"@type": "AggregateOffer",
"offers": [
{
"@type": "Offer",
"name": "title",
"url": "example.com/assets/1"
},
{
"@type": "Offer",
"name": "title 2",
"url": "example.com/assets/2"
},
]
}
}
问题是右括号 } 之后的最后一个 Offer 元素不应该有逗号。元素可以是 1 到 4。实际上一个问题是如何将除最后一个元素之外的所有元素注册为逗号(当然,如果项目为 1,则不要添加)?
LEATH