小编Nik*_*las的帖子

使用php-json-ld进行Google AMP的JSONLD

我在使用"php-json-ld"(github.com/digitalbazaar/php-json-ld)打印Google Accelerated Pages(AMP,www.ampproject.org)的正确JSONLD时遇到问题,如本例所示:github.com /ampproject/amphtml/blob/master/examples/metadata-examples/article-json-ld.amp.html

更具体地说:我想知道如何使用php-json-ld的函数添加"@type":"NewsArticle":

    $doc = (object)array(      
    "https://schema.org/article" => 'Article',
    "http://schema.org/name" => "Manu Sporny",
    "http://schema.org/url" => (object)array("@id" =>     "http://manu.sporny.org/"),
    "http://schema.org/image" => (object)array("@id" => "http://manu.sporny.org/images/manu.png")
);

    $context = (object)array(
    "article" => (object)array("https://schema.org/Article"),
    "name" => "http://schema.org/name",
    "homepage" => (object)array("@id" => "http://schema.org/url", "@type" => "@id"),
    "image" => (object)array("@id" => "http://schema.org/image", "@type" => "@id")
);

    //Print Json-LP
    echo '<script type="application/ld+json">';
    echo json_encode($jsonld_compacted, 
                JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
    echo '</script>';

    //Result:
    <script type="application/ld+json">{
       "@context": "http://schema.org",
       "image": "http://manu.sporny.org/images/manu.png",
       "name": "Manu Sporny",
       "url": "http://manu.sporny.org/"
   }</script>
Run Code Online (Sandbox Code Playgroud)

有人可以帮忙吗?

php schema.org json-ld amp-html

0
推荐指数
2
解决办法
3631
查看次数

标签 统计

amp-html ×1

json-ld ×1

php ×1

schema.org ×1