我正在尝试在推荐中编辑PHP代码循环。 我希望循环从Schema.org库中呈现“审阅”丰富代码段。
<div class="testimonials">
<?php $loop = new WP_Query( array ('post_type' => 'testimonials', 'order' => 'DESC', 'orderby' => 'date', 'showposts' => '99' )); ?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<div class="testimonial">
<?php if (has_post_thumbnail(get_the_ID())) { ?>
<div class="col-md-3 col-sm-4">
<img src="<?php $thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'testimonials_main' ); $url = $thumb['0']; echo $url; ?>" alt="<?php echo the_title(); ?>" />
</div>
<?php } ?>
<div class="col-md-9 col-sm-8">
<div class="testdesc"><?php echo the_content(); ?></div>
<div class="testname"><?php echo the_title(); ?> - <?php echo the_date(); ?></div>
</div>
</div>
<?php endwhile; wp_reset_postdata(); ?>
我想使用上面的代码从Schema.org创建多个Rich Snippets,我想要的摘录如下:-
<script type='application/ld+json'>
{
"@context": "http://schema.org/",
"@type": "Review",
"itemReviewed": "Wedding Hair & Makeup",
"reviewBody": "Hi girls, I was hoping you could pass on a huge thank you to Charmaine “Miss Blue Lily” for my wedding hair and makeup and my Friday night hair. It was completely perfect and I loved how I looked. Charmaine was so accommodating when I was changing my mind and a
delight to have around on the wedding day, a real credit to the Gemma
Sutton team So thank you so much! lots of love, Charlotte xx",
"reviewRating": {
"@type": "Rating",
"bestRating": "5",
"ratingValue": "5",
"worstRating": "0"
},
"author": "Charlotte",
"alternateName": "Wedding Hair & Makeup"
}
</script>
我认为我的代码应该看起来像这样,但是我遇到了问题
<div class="testimonials">
<?php $loop = new WP_Query( array ('post_type' => 'testimonials', 'order' => 'DESC', 'orderby' => 'date', 'showposts' => '99' )); ?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<div class="testimonial">
<?php if (has_post_thumbnail(get_the_ID())) { ?>
<div class="col-md-3 col-sm-4">
<img src="<?php $thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'testimonials_main' ); $url = $thumb['0']; echo $url; ?>" alt="<?php echo the_title(); ?>" />
</div>
<?php } ?>
<div class="col-md-9 col-sm-8">
<div class="testdesc"><?php echo the_content(); ?></div>
<div class="testname"><?php echo the_title(); ?> - <?php echo the_date(); ?></div>
</div>
<script type='application/ld+json'>
{
"@context": "http://schema.org/",
"@type": "Review",
"itemReviewed": "Wedding Hair & Makeup",
"reviewBody": "<?php echo the_content(); ?>",
"reviewRating": {
"@type": "Rating",
"bestRating": "5",
"ratingValue": "5",
"worstRating": "0"
},
"author": "<?php echo the_title(); ?>",
"alternateName": "Wedding Hair & Makeup"
}
</script>
</div>
<?php endwhile; wp_reset_postdata(); ?>
上面的代码没有从数据库中提取严格的值。 我不确定是否应该设置var?