致青春,致梦想,一片自留地

Menu

新接触结构化数据

前言

传说将网页加入结构化资料microdata,有助于搜寻排名。今天浅尝schema.org, 这是由Google、Microsoft、Yandex三大巨头,联手定义的。

资源

成果

折腾了一天,总算定型完成,我的站点都是外贸的产品站点,下列代码不一定适用别人的站点,请自行斟酌。

首页部分

<script type="application/ld+json">
{
    "@context": "https://schema.org",
    "@type": "WebSite",
    "url": "<?php $url = home_url(); echo $url;?>",
    "name": "<?php the_field('sytitle', 'option'); ?>"
}
</script>
<script type="application/ld+json">
{
  "@context": "http://schema.org",
  "@type": "Product",
  "name": "<?php the_field('head_tittle', 'option'); ?>",
  "image": "<?php the_field('head_pic', 'option'); ?>",
  "description":"<?php the_field('sydescription', 'option'); ?>",
  "url":"<?php global $wp; $current_url = home_url(add_query_arg(array(),$wp->request));echo $current_url;?>",
  "brand": "输入产品品牌",
  "sku": "输入产品编号",
  "mpn": "输入产品编号",
  "offers": {
    "@type": "Offer",
    "priceCurrency": "USD",
    "price": "200",
    "url": "<?php global $wp; $current_url = home_url(add_query_arg(array(),$wp->request));echo $current_url;?>",
    "priceValidUntil": "<?php echo date('Y') ?>-12-31",
    "availability": "http://schema.org/InStock",
    "itemCondition": "http://schema.org/NewCondition"
  },
  "aggregateRating": {
    "@type": "AggregateRating",
    "ratingValue": "5",
    "bestRating": "5",
    "worstRating": "0",
    "ratingCount": "500",
    "reviewCount": "500"
  },
    "review":
    [{
    "@type": "Review",
    "name":"输入评论人",
    "reviewBody":"输入评论内容",
    "reviewRating": {"@type": "Rating", "ratingValue": "5"},
    "author": {"@type": "Person", "name": "输入评论人"},
    "publisher": {"@type": "Organization", "name": "输入评论人所在公司"}
   },
    {
    "@type": "Review",
    "name":"输入评论人",
    "reviewBody":"输入评论内容",
    "reviewRating": {"@type": "Rating", "ratingValue": "5"},
    "author": {"@type": "Person", "name": "输入评论人"},
    "publisher": {"@type": "Organization", "name": "输入评论人所在公司"}
    }]
  }
}
</script>

产品页部分

<script type="application/ld+json">
{
  "@context": "https://schema.org",
  "@type": "BreadcrumbList",
  "itemListElement":[
  {
     "@type": "ListItem",
     "position": 1,
     "name": "<?php the_field('sytitle', 'option'); ?>",
     "item": "<?php $url = home_url(); echo $url;?>"
   },
        {
            "@type": "ListItem",
            "position": 2,
            "name": "<?php echo the_title() ?>",
            "item": "<?php global $wp; $current_url = home_url(add_query_arg(array(),$wp->request));echo $current_url;?>"
        }
    ]
}
</script>
<script type="application/ld+json">
{
  "@context": "http://schema.org",
  "@type": "Product",
  "name": "<?php echo the_title() ?>",
  "image": "<?php $full_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full'); echo $full_image_url[0]; ?>",
  "description":"<?php echo the_field('seodescription') ?>",
  "url":"<?php global $wp; $current_url = home_url(add_query_arg(array(),$wp->request));echo $current_url;?>",
  "brand": "输入产品品牌",
  "sku": "输入产品编号<?php the_ID(); ?>",
  "mpn": "输入产品编号<?php the_ID(); ?>",
  "offers": {
    "@type": "Offer",
    "priceCurrency": "USD",
    "price": "200",
    "url": "<?php global $wp; $current_url = home_url(add_query_arg(array(),$wp->request));echo $current_url;?>",
    "priceValidUntil": "<?php echo date('Y') ?>-12-31",
    "availability": "http://schema.org/InStock",
    "itemCondition": "http://schema.org/NewCondition"
  },
  "aggregateRating": {
    "@type": "AggregateRating",
    "ratingValue": "5",
    "bestRating": "5",
    "worstRating": "0",
    "ratingCount": "500",
    "reviewCount": "500"
  },
    "review":
    [{
    "@type": "Review",
    "name":"输入评论人",
    "reviewBody":"输入评论内容",
    "reviewRating": {"@type": "Rating", "ratingValue": "5"},
    "author": {"@type": "Person", "name": "输入评论人"},
    "publisher": {"@type": "Organization", "name": "输入评论人所在公司"}
   },
    {
    "@type": "Review",
    "name":"输入评论人",
    "reviewBody":"输入评论内容",
    "reviewRating": {"@type": "Rating", "ratingValue": "5"},
    "author": {"@type": "Person", "name": "输入评论人"},
    "publisher": {"@type": "Organization", "name": "输入评论人所在公司"}
    }]
  }
}
</script>
— 于 共写了3779个字
— 文内使用到的标签:

2条回应:“新接触结构化数据”

  1. Steven说道:

    It’s actually a cool and useful piece of information. I am happy that you simply shared this helpful information with us. Please keep us informed like this. Thank you for sharing.

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注