Help us understand the problem. What is going on with this article?

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

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>

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

bubbles
仕事ではweb開発をしており、現在はphp(framework:laravel5.4.36)、sqlserver、mysql、javascriptを扱っています。
ayudante
いつもユーザー中心で技術者とコンサルタントがとことん考え抜く それがアユダンテです
https://ayudante.jp/
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした