Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
0
Help us understand the problem. What is going on with this article?
@bubbles

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

More than 1 year has passed since last update.

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
Help us understand the problem. What is going on with this article?
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
bubbles
php、laravel、sqlserver、mysql、javascript、swift。
ayudante
いつもユーザー中心で技術者とコンサルタントがとことん考え抜く それがアユダンテです

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
0
Help us understand the problem. What is going on with this article?