您可以添加一个php变量,并在每次while循环运行时递增它
$args = array(
\'post_type\' => \'events\',
\'order\' => \'ASC\',
);
$wp_query = new WP_Query($args);
?>
<script type="application/ld+json">
{
"@context":"http://schema.org",
"@type":"ItemList",
"itemListElement":[
<?php
$i=0;
while ( have_posts() ) : the_post();
$i++; ?>
{
"@type":"ListItem",
"position":"<?php echo $i; ?>",
"url":"<?php the_permalink(); ?>"
},
<?php endwhile; ?>
]
}
</script>