我有一个优惠券网站,我想在我的优惠券商店页面上添加模式。假设我有一个亚马逊商店,并在亚马逊上添加了5个优惠券帖子。现在,我想将这5个帖子标题和帖子链接添加到模式中。你能告诉我怎么做吗?
下面是我的代码:
<script type="application/ld+json">{
"@context": "http://schema.org",
"@graph": [
{
"@type": "WebPage",
"url": "<?php echo esc_html($taglink);?>",
"image": {
"@type": "ImageObject",
"url": "<?php echo esc_html($brandimage);?>",
"height": 100,
"width": 170
},
"publisher": {
"@type": "Organization",
"name": "Coupon.com",
"logo": {
"@type": "ImageObject",
"url": "https://cdn.coupontac.com/ovowhakr/2020/10/Logo.png.webp",
"width": 500,
"height": 200
}
},
"dateModified": "",
"description":"<?php echo esc_html($schemdesc2);?>",
"name": "",
"headline":"<?php echo esc_html($heading);?>",
"mainEntity": {
"@context": "http://schema.org",
"@type": "Store",
"name": "<?php echo esc_html($tagname);?>",
"image": "<?php echo esc_html($brandimage);?>",
"sameAs": "<?php echo esc_html($weburl);?>",
"aggregateRating": {
"@type": "AggregateRating",
"ratingValue": <?php echo esc_html($userrating);?>,
"ratingCount": <?php echo esc_html($ratingcount);?>,
"bestRating": 5,
"worstRating": 0
},
"description": "<?php echo esc_html($schemdesc);?>",
"makesOffer": [
{
"@type": "Offer",
"name": "",
"url": "",
"description": "",
"validFrom": "",
"validThrough": ""
},
]
}
}
]
}</script>有没有人可以帮我在下面的部分获得5个帖子标题?
"makesOffer": [
{
"@type": "Offer",
"name": "",
"url": "",
"description": "",
"validFrom": "",
"validThrough": ""
},
] 提前谢谢你。
发布于 2021-03-30 16:46:29
您只需通过<head>中所需的post进行查询,而不是使用html模板,而是使用模式模板。
正如你已经在你的例子中展示的,PHP可以进入javascript,因为它是基于服务器的,它首先被呈现。
您不能多次使用"makesOffer"或任何唯一键。你得再重复一遍报价。
您可以针对Google own data testing tool在线测试您的结构化数据。
以下内容基于makesOffer schema.org page example。
<script type="application/ld+json">
[
<?php
$args = array(
'post_type' => 'post',
//...
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) :
while( $query->have_posts() ) :
$query->the_post(); ?>
{
"@context": "https://schema.org",
"@type": "Person",
"name" : "Brent",
"makesOffer" : {
"@type" :"Offer",
"priceSpecification" : {
"@type" : "UnitPriceSpecification",
"priceCurrency" : "USD",
"price" : "18000" },
"itemOffered" : {
"@type" : "Car",
"name" : "<?= wp_strip_all_tags( get_the_title(), true ); ?>",
"description" : "<?= wp_strip_all_tags( get_the_excerpt(), true ); ?>",
"image" : "2009_Volkswagen_Golf_V_GTI_MY09.png",
"color" : "Black",
"numberOfForwardGears" : "6",
"vehicleEngine" : {
"@type": "EngineSpecification",
"name" : "4 cylinder Petrol Turbo Intercooled 2.0 L (1984 cc)"
}
}
}
},
<?php endwhile;
endif;
wp_reset_postdata(); ?>
]
</script>https://stackoverflow.com/questions/66865584
复制相似问题