什么是结构化数据?结构化数据的三种格式及添加方法详解

原创 2025-02-18 08:35:46站长之家
165

结构化数据(Structured Data)是一种标准化的数据格式,用于向搜索引擎提供有关网页内容的额外信息。通过使用结构化数据,搜索引擎可以更好地理解和展示网页内容,从而提高网站的搜索排名和用户体验。本文站长工具网将详细介绍如何在文章类网站中添加结构化数据代码,并提供具体的示例。

JSON-LD.webp

1. 什么是结构化数据?

结构化数据是一种标记方式,用于向搜索引擎提供有关网页内容的额外信息。这些信息通常以特定的格式(如JSON-LD、Microdata或RDFa)嵌入到HTML代码中。搜索引擎(如Google、Bing等)可以读取这些结构化数据,并在搜索结果中以富媒体卡片的形式展示。

2. 常见的结构化数据类型

对于文章类网站,常用的结构化数据类型包括:

  • Article:用于标记文章内容。

  • BreadcrumbList:用于标记面包屑导航。

  • Person:用于标记作者信息。

  • Organization:用于标记组织信息。

3. 如何添加结构化数据

3.1 使用 JSON-LD 格式

JSON-LD 是一种轻量级的结构化数据格式,易于嵌入到 HTML 中。以下是一个示例,展示了如何在文章类网站中添加 JSON-LD 格式的结构化数据。

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>文章标题</title>
    <script type="application/ld+json">
    {
      "@context": "https://schema.org",
      "@type": "Article",
      "headline": "文章标题",
      "description": "文章描述",
      "url": "https://example.com/article-url",
      "image": [
        "https://example.com/image1.jpg",
        "https://example.com/image2.jpg"
      ],
      "datePublished": "2023-10-01T12:00:00Z",
      "dateModified": "2023-10-02T12:00:00Z",
      "author": {
        "@type": "Person",
        "name": "作者姓名",
        "url": "https://example.com/author-profile"
      },
      "publisher": {
        "@type": "Organization",
        "name": "组织名称",
        "logo": {
          "@type": "ImageObject",
          "url": "https://example.com/logo.png"
        }
      },
      "mainEntityOfPage": {
        "@type": "WebPage",
        "@id": "https://example.com/article-url"
      }
    }
    </script>
</head>
<body>
    <article>
        <h1>文章标题</h1>
        <p>文章描述</p>
        <p>文章内容...</p>
    </article>
</body>
</html>

3.2 使用 Microdata 格式

Microdata 是另一种常用的结构化数据格式,通过在 HTML 元素中添加特定的属性来标记数据。以下是一个示例,展示了如何在文章类网站中添加 Microdata 格式的结构化数据。

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>文章标题</title>
</head>
<body>
    <article itemscope itemtype="https://schema.org/Article">
        <h1 itemprop="headline">文章标题</h1>
        <p itemprop="description">文章描述</p>
        <p itemprop="articleBody">文章内容...</p>
        <time itemprop="datePublished" datetime="2023-10-01T12:00:00Z">2023年10月1日</time>
        <time itemprop="dateModified" datetime="2023-10-02T12:00:00Z">2023年10月2日</time>
        <img itemprop="image" src="https://example.com/image1.jpg" alt="图片描述">
        <span itemprop="author" itemscope itemtype="https://schema.org/Person">
            <span itemprop="name">作者姓名</span>
            <a itemprop="url" href="https://example.com/author-profile">作者主页</a>
        </span>
        <div itemprop="publisher" itemscope itemtype="https://schema.org/Organization">
            <span itemprop="name">组织名称</span>
            <img itemprop="logo" src="https://example.com/logo.png" alt="组织Logo">
        </div>
    </article>
</body>
</html>

3.3 使用 RDFa 格式

RDFa 是一种扩展属性语言,用于在 HTML 中嵌入结构化数据。以下是一个示例,展示了如何在文章类网站中添加 RDFa 格式的结构化数据。

<!DOCTYPE html>
<html lang="zh-CN" prefix="og: http://ogp.me/ns# schema: https://schema.org/">
<head>
    <meta charset="UTF-8">
    <title>文章标题</title>
</head>
<body>
    <article vocab="https://schema.org/" typeof="Article">
        <h1 property="headline">文章标题</h1>
        <p property="description">文章描述</p>
        <p property="articleBody">文章内容...</p>
        <time property="datePublished" datetime="2023-10-01T12:00:00Z">2023年10月1日</time>
        <time property="dateModified" datetime="2023-10-02T12:00:00Z">2023年10月2日</time>
        <img property="image" src="https://example.com/image1.jpg" alt="图片描述">
        <span property="author" typeof="Person">
            <span property="name">作者姓名</span>
            <a property="url" href="https://example.com/author-profile">作者主页</a>
        </span>
        <div property="publisher" typeof="Organization">
            <span property="name">组织名称</span>
            <img property="logo" src="https://example.com/logo.png" alt="组织Logo">
        </div>
    </article>
</body>
</html>

4. 测试和验证

添加结构化数据后,建议使用 Google 的结构化数据测试工具(Structured Data Testing Tool)进行验证。该工具可以帮助你检查结构化数据是否正确,并提供改进建议。

4.1 使用 Google 结构化数据测试工具

  1. 访问 Google 结构化数据测试工具

  2. 输入你的网页 URL 或者直接粘贴 HTML 代码。

  3. 点击“运行测试”按钮。

  4. 查看测试结果,确保所有结构化数据都正确无误。

5. 总结

通过在文章类网站中添加结构化数据,可以提高搜索引擎对网页内容的理解和展示效果。本文介绍了三种常用的结构化数据格式(JSON-LD、Microdata和RDFa),并提供了具体的示例代码。希望这些示例能够帮助你更好地理解和应用结构化数据,提升网站的搜索排名和用户体验。

结构化数据
THE END
站长工具箱
专注软件和工具分享

相关推荐

Schema标记是什么?为什么Schema结构化数据对SEO优化很重要?
在SEO(搜索引擎优化)的广阔领域中,Schema标记(也被称为结构化数据标记)如同一座桥梁,连接着网站内容与搜索引擎的理解能力,其重要性日益凸显。本文站长工具网将详细探讨Sch...
2025-02-18 站长之家
177

浅谈结构化数据对网站SEO搜索引擎优化的影响
随着互联网技术的发展,搜索引擎优化(SEO)已经成为提升网站流量和曝光度的重要手段。在众多SEO策略中,结构化数据的应用逐渐成为提升网站排名和用户体验的关键因素之一。本...
2024-08-31 站长之家
272