0WordPress的标志丰富的片段代码奥秘2.X

In addition to this site I have a personal blog 哪里, amongst other things, 我张贴的食谱. I’ve recently discovered google’s new recipe search, and have been looking to implement support for microformats / 微数据. Google provide a tool for checking your markup, 叫 “丰富网页摘要测试工具“. When I tried validating one of my recipes, I encountered various errors, 已经采取了我一段时间来追查和解决.

Each one is independent, but related, and in all cases the number of errors you are likely to encounter depends largely on the theme you use with your blog. In my case, using the mystique theme, I encountered a substantial number of errors.

1. The first problem was with the author information / hrecipe section

解决方案:

You need a google profile. Your google profile must be linked from somewhere on the page, with rel=”我”, AND the main domain of your website must be listed on your google profile links.

I achieved this with the Mystique theme with a series of modifications.

首先, 我加入了代码 yoast (如下所示) 添加到functions.php

[PHP]功能yoast_add_google_profile( $contactmethods ) {
// 加入谷歌简介
$contactmethods[‘google_profile’] = ‘Google Profile 网址’;
返回$ contactmethods;
}
的add_filter( ‘user_contactmethods’, ‘yoast_add_google_profile’, 10, 1);[/PHP]

第二, I went to my wordpress profile page and filled in the google profile field with a link to my google profile

第三, 我编辑一行author.php, 再次, based on information from yoast, but changed for the Mystique theme

in this section

[PHP]
如果(($curauth->user_url<>’http://’) && ($curauth->user_url<>”)) 回声 ‘

‘.__(‘Homepage:’,’mystique’).’ <a href="’.$curauth->user_url.’">’.$curauth->user_url.'</一>

';
如果($curauth->yim<>”) 回声 ‘

‘.__(‘Yahoo Messenger:’,’mystique’).’ <a href="ymsgr:sendIM?’.$curauth->yim.’">’.$curauth->yim.'</一>

';
如果($curauth->jabber<>”) 回声 ‘

‘.__(‘Jabber/GTalk:’,’mystique’).’ <a href="gtalk:chat?jid=’.$curauth->jabber.’">’.$curauth->jabber.'</一>

';
如果($curauth->aim<>”) 回声 ‘

‘.__(‘AIM:’,’mystique’).’ <a href="aim:goIM?screenname=’.$curauth->aim.’">’.$curauth->aim.'</一>

';
[/PHP]

add this extra line

[php highlight=”5″]
如果(($curauth->user_url<>’http://’) && ($curauth->user_url<>”)) 回声 ‘

‘.__(‘Homepage:’,’mystique’).’ <a href="’.$curauth->user_url.’">’.$curauth->user_url.'</一>

';
如果($curauth->yim<>”) 回声 ‘

‘.__(‘Yahoo Messenger:’,’mystique’).’ <a href="ymsgr:sendIM?’.$curauth->yim.’">’.$curauth->yim.'</一>

';
如果($curauth->jabber<>”) 回声 ‘

‘.__(‘Jabber/GTalk:’,’mystique’).’ <a href="gtalk:chat?jid=’.$curauth->jabber.’">’.$curauth->jabber.'</一>

';
如果($curauth->aim<>”) 回声 ‘

‘.__(‘AIM:’,’mystique’).’ <a href="aim:goIM?screenname=’.$curauth->aim.’">’.$curauth->aim.'</一>

';
如果($curauth->google_profile<>”) 回声 ‘
<a href="’ . $curauth->google_profile . '" rel="me">Google Profile</一>

';
[/PHP]

下一个, I edited single.php to add rel=”作者” to the link to my author page. In the Mystique theme this is found towards the bottom of the file, within the (long) 线(s) 如下所示. I have added the rel=”作者” at the end of the first line before the href=” 部分

[PHP]
printf的(__(‘This entry was posted by %1$s on %2$s at %3$s, and is filed under %4$s. Follow any responses to this post through %5$s.’, ‘mystique’), '<a title="’. sprintf(__(" href="’. get_author_posts_url(get_the_author_meta(‘ID’)) .’" rel="author">’. get_the_author() .“</一>’,
get_the_time(获取选项(‘date_format’)),get_the_time(获取选项(‘time_format’)), get_the_category_list(', '), '<a title="RSS 2.0" href="’.get_post_comments_feed_link($后>ID).’">RSS 2.0</一>’);回声 ‘ ';
[/PHP]

然后, finally add the same rel=”作者” to line 670 of core.php

When this is correctly implemented you should get a success message in the snippets testing tool which reads Verified: Authorship markup is correct for this page

2. 第二个问题(s) 均与hfeed / hentry section and included the following:

很有用的文章 “作者”.
警告: 至少一个字段必须为hCard的设置.
警告: 至少一个字段必须为HatomEntry设置.
警告: 缺少必填字段 “入门称号”.
警告: 缺少必填字段 “更新”.
警告: 很有用的文章 “作者”.

解决方案(s):

Use the wordpress editor to edit single.php

查找代码

[xhtml]</pre>
<h1 class="title"></H1>
<pre>
[/xhtml]

replace this with

[xhtml]</pre>
<h1 class="title entry-title"></H1>
<h2 class="updated"></h2>
<h2 class="vcard"></h2>
<pre>
[/xhtml]

A final noteDon’t just copy and paste the code from this page, as for some reason (I’m guessing character encoding) 它不会工作. Copy it from here and paste into windows notepad. Then re-copy it from windows notepad (or any other basic plain-text-only editor) and paste into the wordpress editor. Going via notepad loses any hidden encoding or other data which causes a problem so the code is treated as the plain-text it is supposed to be

你怎么看? 请给我们一个评论如下! 如果您想订阅,请使用菜单上的订阅链接右上方. 您还可以通过使用下面的链接社会分享这与你的朋友. 干杯.

发表评论