我试图在我当前的WordPress项目上实现JSON-LD标记并遇到我所理解的相当常见的问题:SDTT响应一个" URL必须指向同一页面"错误。
根据this page的建议,我修改了我的代码 但错误仍然弹出。
$mup = '{'."\n";
$mup .= ' "@type":"ListItem",'."\n";
$mup .= ' "position":'. ($i-1) .','."\n";
$mup .= ' "item": {'."\n";
$mup .= ' "@type" : "Report",'."\n";
$mup .= ' "author":"'. get_bloginfo('name') .'",'."\n";
$mup .= ' "publisher":{'."\n";
$mup .= ' "@type": "Organization",'."\n";
$mup .= ' "name": "'. get_bloginfo('name') .'",'."\n";
$mup .= ' "logo": "'. $image[0]. '"'."\n";
$mup .= ' },'."\n";
$mup .= ' "datePublished": "'. get_the_date("Y-m-d") .'",'."\n";
$mup .= ' "headline" : "'. get_the_title() .'",'."\n";
$mup .= ' "description" : "'.get_the_excerpt().'",'."\n";
$mup .= ' "genre" : "Case study",'."\n";
$mup .= ' "url":"'. get_permalink() .'"'."\n";
$mup .= ' }'."\n";
$mup .= ' }';
$markup[] = $mup;
在页脚中:
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "ItemList",
"itemListElement": [<?php echo (join(",\n", $markup))."\n" ?>]
}
</script>
生成代码的示例:
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "ItemList",
"itemListElement": [{
"@type":"ListItem",
"position":1,
"item": {
"@type" : "Report",
"author":"RPA導入コンサルティング会社・RPAツール・RPAソフトを徹底比較",
"publisher":{
"@type": "Organization",
"name": "RPA導入コンサルティング会社・RPAツール・RPAソフトを徹底比較",
"logo": "http://rpa-media.net/wp-content/uploads/2018/04/logo.png"
},
"datePublished": "2018-04-04",
"headline" : "事例1",
"description" : "",
"genre" : "Case Study",
"url":"http://rpa-media.net/case-study/%e4%ba%8b%e4%be%8b%ef%bc%91/"
}
}
]
}
</script>
美化代码:
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "ItemList",
"itemListElement": [{
"@type": "ListItem",
"position": 1,
"item": {
"@type": "Report",
"author": "RPA導入コンサルティング会社・RPAツール・RPAソフトを徹底比較",
"publisher": {
"@type": "Organization",
"name": "RPA導入コンサルティング会社・RPAツール・RPAソフトを徹底比較",
"logo": "http://rpa-media.net/wp-content/uploads/2018/04/logo.png"
},
"datePublished": "2018-04-04",
"headline": "事例1",
"description": "",
"genre": "Case Study",
"url": "http://rpa-media.net/case-study/%e4%ba%8b%e4%be%8b%ef%bc%91/"
}
}]
}
</script>
此代码生成错误BUT,如果我采用生成的代码,在Atom中美化它然后在SDTT中使用它,则错误消失。
如果我尝试直接在页面上使用美化生成的代码(因为没有PHP),则会出现错误。
我能以任何方式正确实施吗?我的数据结构糟糕吗?或者是我输出它的方式?