I have a coupon website and I want to add schema on my coupon store page. suppose I have an amazon store and added 5 coupon posts on amazon. Now, I want to add these 5 post titles and post links to the schema. could you please tell me how can I do it?
Below is my code:
<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>
can any one help me to get 5 post title on below section ?
"makesOffer": [
{
"@type": "Offer",
"name": "",
"url": "",
"description": "",
"validFrom": "",
"validThrough": ""
},
]
Thank you in advance.
You would simply query through the required post from the <head>
, but instead of using an html template you would use a schema one.
As you already showed in your example, PHP can go inside javascript as it is server based, it is rendered first.
You can't use "makesOffer"
or any unique key multiple times. You have to repeat the offer.
You can test your structured data online against Google own data testing tool.
The following is based on the 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>