ผลลัพธ์ที่ได้
โค้ด: เลือกทั้งหมด
<script type="application/ld+json">
{
"@context": "https://schema.org/",
"@type": "Product",
"name" : "น้ำ",
"image" : "https://upload.wikimedia.org/wikipedia/commons/thumb/4/41/Iceberg_with_hole_near_Sandersons_Hope_2007-07-28_2.jpg/220px-Iceberg_with_hole_near_Sandersons_Hope_2007-07-28_2.jpg"",
"description" : "
น้ำเป็นสารประกอบอนินทรีย์ที่โปร่งใส ไม่มีรส ไม่มีกลิ่น",
"review": {
"@type": "Review",
"reviewRating": {
"@type": "Rating",
"ratingValue": "2.0",
"ratingCount": "1"
},
"author": {
"@type": "Person",
"name": "admin"
}
},
"aggregateRating": {
"@type": "AggregateRating",
"ratingValue" : "2.0",
"ratingCount" : "1"
},
"offers" : {
"@type": "Offer",
"url": "",
"price": "5",
"priceCurrency": "THB"
},
"brand": {
"@type": "Brand",
"name": "test"
}
}
</script>
โค้ดใน php
โค้ด: เลือกทั้งหมด
$description = $article->metadesc != "" ? substr(strip_tags($article->metadesc), 0, 160) : ($article->text != "" ? substr(strip_tags($article->text), 0, 160) : '');
$document->addScriptDeclaration('
{
"@context": "https://schema.org/",
"@type": "Product",
"name" : "'.$name.'",
"image" : "'.$getimage.'",
"description" : "'.$description.'",
"review": {
"@type": "Review",
"reviewRating": {
"@type": "Rating",
"ratingValue": "'.$rating.'",
"ratingCount": "'.$rating_count.'"
},
"author": {
"@type": "Person",
"name": "'.$author.'"
}
},
"aggregateRating": {
"@type": "AggregateRating",
"ratingValue" : "'.$rating.'",
"ratingCount" : "'.$rating_count.'"
},
"offers" : {
"@type": "Offer",
"url": "'.$link.'",
"price": "'.$price_product.'",
"priceCurrency": "THB"
},
"brand": {
"@type": "Brand",
"name": "'.$brand.'"
}
}
', 'application/ld+json');