0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【SEO】【構造化データ】Product(複数)

Last updated at Posted at 2020-05-29

##Product
以下の実装をしたケースの紹介です。
https://developers.google.com/search/docs/data-types/product?hl=ja

今回のページの場合は売り物ではなく全国の車のカタログのため推奨フィールドは空が多いです。
ただこのようなケースでも必須フィールドを埋めれば適用することができます。

##コード
テンプレート側にベタ書きでも良かったのですがテンプレートはなるべくスッキリさせたいのと元々裏側でforeachしていたのでそこに入れ込みたく、値を変数に入れてテンプレート側で表示するようにしました。

今回はこちらのページに実装した例です。

structuredData.php

foreach($cars as $key=>$car){
  $structuredData[] = array(
    "@context" => "https://schema.org",
    "@type" => "Product",
    "name" => $car['Name'],
    "image" => $car['ImagePath'],
    "url" => $car['PageUrl'],
    "brand" => array(
      "@type" => "Brand",
      "name" => $car['BrandName']
    ),
    "offers" => array(
      "@type" => "Offer",
      "price" => $car['Price'],
      "priceCurrency" => "JPY"
    ),
  );
}
$structuredData = json_encode($structuredData);
structuredData.template
<script type="application/ld+json">
<?php
if(isset($structuredData) && !empty($structuredData)){
    if($structuredData != '[]'){
        echo $structuredData;
    }
}
?>
</script>

テストツールで見るとこんな感じです。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?