exs/schema-breadcrumb-bundle

此插件生成面包屑的微数据。

v0.0.3 2017-11-08 19:53 UTC

This package is auto-updated.

Last update: 2024-08-29 04:58:52 UTC


README

Build Status

这个插件做什么?

此插件生成包含schema.org定义的BreadcrumbList对象所需的json对象的<script>标签。

来源: http://schema.org/BreadcrumbList

安装

使用composer添加此插件

$ composer require exs/schema-breadcrumb-bundle

在kernel中启用插件

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new EXS\SchemaBreadcrumbBundle\EXSSchemaBreadcrumbBundle(),
        // ...
    );
}

使用方法

示例

<!DOCTYPE html>
<html>
    <head>
        ...
        {{ getJsonBreadcrumb([
            {
                'name': 'Category One',
                'url': 'http://www.test.tld/category-one',
                'image': 'http://www.test.tld/images/category-one.png'
            },
            {
                'name': 'Subcategory Two',
                'url': 'http://www.test.tld/category-one/subcategory-two'
            },
            {
                'name': 'Element Three',
                'url': 'http://www.test.tld/category-one/subcategory-two/element-three'
            }
        ]) }}
    </head>
    <body>
        ...
    </body>
</html>

数组中元素的顺序用于定义面包屑中元素的顺序。

上述示例将生成ld+json标签

<script type="application/ld+json">
{
    "@context": "http://schema.org",
    "@type": "BreadcrumbList",
    "itemListElement": [
        {
            "@type": "ListItem",
            "position": 1,
            "item": {
                "@id": "http://www.test.tld/category-one",
                "name": "Category One",
                "image": "http://www.test.tld/images/category-one.png"
            }
        },
        {
            "@type": "ListItem",
            "position": 2,
            "item": {
                "@id": "http://www.test.tld/category-one/subcategory-two",
                "name": "Subcategory Two"
            }
        },
        {
            "@type": "ListItem",
            "position": 3,
            "item": {
                "@id": "http://www.test.tld/category-one/subcategory-two/element-three",
                "name": "Element Three"
            }
        }
    ]
}
</script>

并被搜索引擎解释为类似面包屑的结构

Category One > Subcategory Two > Element Three