pasckr 发表于 2016-5-12 18:17:05

修复Wordpress的Google丰富网页摘要错误






              最近在使用Google丰富网页摘要教程的时候,发现对于默认Wordpress博客,总会有三条错误信息出现,今天我就介绍一下,如何通过修改Wordpress模版文件来修复这些错误信息的方法。
错误信息内容分别是:
Warning: Missing required field “entry-title”。
Warning: Missing required field “updated”。
Warning: Missing required hCard “author”。
http://img10.3lian.com/edu121104/g/g106/201210/4f73fce188e45506af91583aee551698.jpg
对于entry-title的错误信息修改方法是:
打开single.php文件,找到类似<h1><?php the_title(); ?></h1>一行,将其修改为<h1 class=&quot;entry-title title&quot;><?php the_title(); ?></h1>(有些模版可能是h2或其他)
对于updated的错误信息修改方法是:
打开single.php文件,找到<?php the_date();?>一行,将其修改为<div class=&quot;updated date&quot;><?php the_time('F S, Y'); ?></div>
对于author的错误信息修改方法是:
打开single.php文件,找到<?php the_author(); ?>一行,将其修改为<span class=&quot;author vcard&quot;><span class=&quot;fn&quot;><?php the_author(); ?></span></span>
另外,在昨天写的&ldquo;Google丰富网页摘要教程&rdquo;中,有些读者希望能举个Wordpress模版修改的例子,下面就是一个Wordpress模版的例子。
打开single.php文件,在适当位置添加如下代码:
<?php
$separator = '&rsaquo;';
$category = get_the_category();
if ($category) {
foreach($category as $category) {
echo'<div itemscope itemtype=&quot;http://data-vocabulary.org/Breadcrumb&quot; style=&ldquo;display:inline&quot;>';
echo $separator.&quot;<a href=&quot;&quot;.get_category_link($category->term_id).&quot;&quot; itemprop=&quot;url&quot;><span itemprop=&quot;title&quot;>$category->name</span></a>
&quot;;
echo'</div>';
}}
?>
文章来源:月光博客,转载请注明出处。
页: [1]
查看完整版本: 修复Wordpress的Google丰富网页摘要错误