最近在使用Google豐富網頁摘要測試載入器的時候,發現對於預設Wordpress部落格,總會有三條錯誤資訊出現,今天我就介紹一下,如何通過修改Wordpress模版檔案來修複這些錯誤資訊的方法。
錯誤資訊內容分別是:
Warning: Missing required field "entry-title".
Warning: Missing required field "updated".
Warning: Missing required hCard "author".
對於entry-title的錯誤資訊修改方法是:
開啟single.php檔案,找到類似<h1><?php the_title(); ?></h1>一行,將其修改為<h1 class="title entry-title"><?php the_title(); ?></h1>(有些模版可能是h2或其他)
對於updated的錯誤資訊修改方法是:
開啟single.php檔案,找到<?php the_date();?>一行,將其修改為<div class="date updated"><?php the_time('F S, Y'); ?></div>
對於author的錯誤資訊修改方法是:
開啟single.php檔案,找到<?php the_author(); ?>一行,將其修改為<span class="vcard author"><span class="fn"><?php the_author(); ?></span></span>
另外,在昨天寫的“Google豐富網頁摘要教程”中,有些讀者希望能舉個Wordpress模版修改的例子,下面就是一個Wordpress模版的例子。
開啟single.php檔案,在適當位置添加如下代碼:
<?php
$separator = '›';
$category = get_the_category();
if ($category) {
foreach($category as $category) {
echo '<div itemscope itemtype="http://data-vocabulary.org/Breadcrumb" style="display:inline">';
echo $separator . "<a href=\"".get_category_link($category->term_id)."\" itemprop=\"url\"><span itemprop=\"title\">$category->name</span></a>
";
echo '</div>';
}}
?>