<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Soul Of Free Loop &#187; Google</title>
	<atom:link href="https://zohead.com/archives/tag/google/feed" rel="self" type="application/rss+xml" />
	<link>https://zohead.com</link>
	<description>Uranus Zhou&#039;s Blog</description>
	<lastBuildDate>Sat, 19 Jul 2025 15:42:46 +0000</lastBuildDate>
	<language>zh-CN</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.8</generator>
	<item>
		<title>WordPress 3.8开启Google AMP的问题</title>
		<link>https://zohead.com/archives/wordpress-3-amp/</link>
		<comments>https://zohead.com/archives/wordpress-3-amp/#comments</comments>
		<pubDate>Tue, 01 Aug 2017 17:37:56 +0000</pubDate>
		<dc:creator><![CDATA[Uranus Zhou]]></dc:creator>
				<category><![CDATA[Google]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[AMP]]></category>
		<category><![CDATA[AMP for WP]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[qTranslate]]></category>
		<category><![CDATA[插件]]></category>

		<guid isPermaLink="false">https://zohead.com/?p=1487</guid>
		<description><![CDATA[关于 AMP Accelerated Mobile Pages（简称 AMP）是 Google 带领开发的开源项目，主要为了提升移动设备对网站的访问速度，大概包括 AMP HTML、AMP JS 和 AMP Cache 三部分，非常适合博客及新闻展示类的静态网站。 有关 AMP 的详细介绍可以参考其官方网站： https://www.ampproject.org/zh_cn/ AMP 网页只能使用 AMP HTML 中允许的有限的标签，不允许使用 AMP Runtime、AMP Components 之外的 JS，而且 AMP Runtime、Components 都必须从 cdn.amppr [&#8230;]]]></description>
				<content:encoded><![CDATA[<h2 id="about-amp">关于 AMP</h2>
<p><a href="https://en.wikipedia.org/wiki/Accelerated_Mobile_Pages" target="_blank">Accelerated Mobile Pages</a>（简称 AMP）是 Google 带领开发的开源项目，主要为了提升移动设备对网站的访问速度，大概包括 <strong>AMP HTML</strong>、<strong>AMP JS</strong> 和 <strong>AMP Cache</strong> 三部分，非常适合博客及新闻展示类的静态网站。</p>
<p>有关 AMP 的详细介绍可以参考其官方网站：</p>
<p><a href="https://www.ampproject.org/zh_cn/" target="_blank">https://www.ampproject.org/zh_cn/</a></p>
<p>AMP 网页只能使用 AMP HTML 中允许的有限的标签，不允许使用 AMP Runtime、AMP Components 之外的 JS，而且 AMP Runtime、Components 都必须从 <code>cdn.ampproject.org</code> 加载，因此目前 AMP 网页都必须在翻墙状态下才能正常浏览。</p>
<p>AMP Cache 是负责缓存并传输 AMP 页面的 CDN 服务器，用户在 Google 移动端中点击 AMP 网站时，实际访问的是缓存过的页面。</p>
<h2 id="wordpress-amp-problem">WordPress 启用 AMP 的问题</h2>
<p>WordPress 官方提供了 <a href="https://wordpress.org/plugins/amp/" target="_blank">AMP</a> 插件以支持直接为博客开启 AMP 加速，只是官方插件要求 WordPress 最低为 4.4 版本。</p>
<p>由于我的博客安装了 <a href="http://www.qianqin.de/qtranslate/" target="_blank">qTranslate</a> 这款多语言插件，而该插件却只支持到 WordPress 3.8.1 版本，如果升级 WordPress 到最新版本，qTranslate 插件就会自动禁用。然而 qTranslate 插件是对 WordPress 数据库直接进行修改的，禁用之后博客文章就可能会同时显示多种语言的内容，这样显然是不可接受的。</p>
<p>虽然网上已经有人继承 qTranslate 原作发布了例如 qTranslate X 之类的支持新版本 WordPress 的插件，但为了数据安全（其实是懒）考虑我暂时还是不打算直接升级 WordPress 了。</p>
<p>不过还好我在 WordPress 插件库里找到一款看起来支持 WordPress 3.8 的 AMP 插件：<a href="https://wordpress.org/plugins/accelerated-mobile-pages/" target="_blank">AMP for WP</a>，毕竟看此插件的介绍和评分都比官方的 AMP 插件要强哦，而且最低只要求 WordPress 3.0 版本。</p>
<p>AMP for WP 安装起来还是非常顺利的，插件选项里目前基本只提供了 Google Analytics UID 的设置选项，启用之后访问 AMP 版网站的方法是在地址后面加上 <code>?wpamp</code> 后缀。</p>
<p>不过我刚开始测试访问 AMP 首页和文章就碰到问题了，直接没有任何显示了，看网页源代码输出信息不全，显然是 AMP for WP 插件对老版本 WordPress 兼容性还是有点问题。</p>
<h2 id="mod-amp-for-wp">修改 AMP for WP</h2>
<p>首先修改 AMP for WP 插件的 <code>wp-amp-ninja/admin/common.php</code> 文件，打开 PHP 报错开关：</p>
<pre class="brush: php; title: wp-amp-ninja/admin/common.php; notranslate">
error_reporting(1);
</pre>
<p>这下访问博客首页和文章页面就能看到详细报错了：</p>
<pre class="brush: plain; title: ; notranslate">
Fatal error: Call to undefined function get_the_permalink() in /www/zohead.com/wp-content/plugins/wp-amp-ninja/includes/wpamp-front.php on line 24

Fatal error: Call to undefined function the_posts_pagination() in /www/zohead.com/wp-content/plugins/wp-amp-ninja/template/wpamp-content.php on line 53


Fatal error: Call to undefined function the_archive_title() in /www/zohead.com/wp-content/plugins/wp-amp-ninja/includes/wpamp-functions.php on line 600

Fatal error: Call to undefined function the_archive_description() in /www/zohead.com/wp-content/plugins/wp-amp-ninja/includes/wpamp-functions.php on line 601
</pre>
<p>经过查阅 WordPress 官方文档发现：</p>
<ol>
<li><a href="https://developer.wordpress.org/reference/functions/get_the_permalink/" target="_blank">get_the_permalink</a> 函数在 WordPress 3.9.0 版本开始引入，其实就是 1.0.0 版本就已经有的 <a href="https://developer.wordpress.org/reference/functions/get_permalink/" target="_blank">get_permalink</a> 函数；</li>
<li><a href="https://developer.wordpress.org/reference/functions/the_posts_pagination/" target="_blank">the_posts_pagination</a> 函数在 WordPress 4.1.0 版本开始引入，一同引入的还有 <code>the_posts_navigation</code> 函数，与 <code>get_the_permalink</code> 函数一样都位于 WordPress 代码库的 <code>wp-includes/link-template.php</code> 文件；</li>
<li>至于 <a href="https://developer.wordpress.org/reference/functions/the_archive_title/" target="_blank">the_archive_title</a> 和 <a href="https://developer.wordpress.org/reference/functions/the_archive_description" target="_blank">the_archive_description</a> 函数的功能比较类似，支持显示文章的标题和描述并在前后插入自定义代码，同样也在 WordPress 4.1.0 版本开始引入，位于 WordPress 代码库的 <code>wp-includes/general-template.php</code> 文件。</li>
</ol>
<p>由此可见，AMP for WP 实际上应该至少要求 WordPress 4.1.0 版本，只是作者并没有测试过是否兼容较低版本的 WordPress。</p>
<p>不过还好我看了下 WordPress 最新 4.8 版本的代码，上面缺少的几个 WordPress 内置函数都是功能比较独立的。</p>
<p>因此我稍微修改了一下博客目录下的 <code>link-template.php</code> 和 <code>general-template.php</code> 文件，将最新版本的 <code>get_the_permalink</code>、<code>the_posts_pagination</code>、<code>the_posts_navigation</code>、<code>the_archive_title</code>、<code>the_archive_description</code> 函数实现分别 Backport 到 WordPress 3.8 版本。Backport 完成之后再访问博客首页和文章，就没有 PHP 报错了。</p>
<p>不过初步试用下来，我还是发现 AMP for WP 插件的一些小问题：</p>
<ol>
<li>如果通过 qTranslate 插件访问博客的英文版本（通过增加 <code>?lang=en</code> 地址后缀），对应的 AMP 版页面地址会不正确，AMP for WP 插件在转换地址时并没有考虑地址中会带有其它后缀的情况；</li>
<li>AMP for WP 对于带有多种语言标题的文章直接显示数据库中多种语言合并在一起的标题效果，而并不是 qTranslate 插件根据客户端语言自动处理后的效果，这个问题在我使用的几个 WordPress 主题中都不会出现；</li>
<li>文章中插入的多行代码被合并成一行显示了，这是明显不能接受的；</li>
<li>文章的中文发表时间无法正确显示，统一显示为当前日期。</li>
</ol>
<p>第一个问题需要修改 AMP for WP 插件的 <code>wpamp-front.php</code>、<code>wpamp-functions.php</code>、<code>wpamp-header.php</code> 这几个文件中转换地址的代码，例如 <code>wpamp-front.php</code> 文件的修改：</p>
<pre class="brush: diff; title: wpamp-front.php; notranslate">
 		$the_permalink = get_the_permalink( $post-&gt;ID );
 	}
 	
-	$the_permalink = rtrim( $the_permalink, '/' ) . '/';
+	$the_permalink = rtrim( $the_permalink, '/' );
 	$perma = strpos( $the_permalink, &quot;?&quot; );
 	if ( $perma === false ) {
+		$the_permalink .= '/';
 		$sConnector = &quot;?&quot;;
 	} else {
 		$sConnector = &quot;&amp;&quot;;
</pre>
<p>第二个问题需要修改 <code>wpamp-content.php</code> 文件，文章标题要做 <code>apply_filters</code> 处理：</p>
<pre class="brush: diff; title: wpamp-content.php; notranslate">
                 &lt;div id=&quot;amp-pagination&quot;&gt;
                 	&lt;?php $prev_post = get_previous_post(); if (!empty( $prev_post )): ?&gt;
-                    	&lt;div class=&quot;prev&quot;&gt;&lt;a href=&quot;&lt;?php echo wp_amp_permalink($prev_post-&gt;ID, AMP_CONSTANT); ?&gt;&quot;&gt; &amp;laquo; &lt;?php echo $prev_post-&gt;post_title ?&gt;&lt;/a&gt;&lt;/div&gt;
+                    	&lt;div class=&quot;prev&quot;&gt;&lt;a href=&quot;&lt;?php echo wp_amp_permalink($prev_post-&gt;ID, AMP_CONSTANT); ?&gt;&quot;&gt; &amp;laquo; &lt;?php echo apply_filters( 'the_title', $prev_post-&gt;post_title, $prev_post-&gt;ID ); ?&gt;&lt;/a&gt;&lt;/div&gt;
 					&lt;?php endif ?&gt;
 					&lt;?php  $next_post = get_next_post(); if (!empty( $next_post )): ?&gt;
-                        &lt;div class=&quot;next&quot;&gt;&lt;a href=&quot;&lt;?php echo wp_amp_permalink($next_post-&gt;ID, AMP_CONSTANT); ?&gt;&quot;&gt;&lt;?php echo $next_post-&gt;post_title ?&gt; &amp;raquo; &lt;/a&gt;&lt;/div&gt;
+                        &lt;div class=&quot;next&quot;&gt;&lt;a href=&quot;&lt;?php echo wp_amp_permalink($next_post-&gt;ID, AMP_CONSTANT); ?&gt;&quot;&gt;&lt;?php echo apply_filters( 'the_title', $next_post-&gt;post_title, $next_post-&gt;ID ); ?&gt; &amp;raquo; &lt;/a&gt;&lt;/div&gt;
 					&lt;?php endif ?&gt;
                     &lt;div class=&quot;clearfix&quot;&gt;&lt;/div&gt;
                 &lt;/div&gt;
</pre>
<p>第三个问题就比较简单了，将 <code>simple_html_dom.php</code> 文件中替换回车和换行符的处理去掉就可以了。</p>
<p>第四个文章发表时间的问题也可以修改 <code>wpamp-content.php</code> 文件简化处理：</p>
<pre class="brush: diff; title: wpamp-content.php; notranslate">
                     &lt;?php endif; ?&gt;
                     By &lt;span class=&quot;amp-wp-author&quot;&gt;&lt;a href=&quot;&lt;?php echo wp_amp_permalink( NULL, AMP_CONSTANT, get_author_posts_url( get_the_author_meta( 'ID' ) ) ); ?&gt;&quot;&gt;&lt;?php echo esc_html( get_the_author() ); ?&gt;&lt;/a&gt;&lt;/span&gt;
-                    &lt;?php $the_time = date_i18n( get_option( 'date_format' ), strtotime( get_the_time('F jS, Y') ) ); ?&gt;
-                    on &lt;time datetime=&quot;&lt;?php echo $the_time; ?&gt;&quot;&gt;&lt;?php echo $the_time; ?&gt;&lt;/time&gt;
+                    on &lt;time datetime=&quot;&lt;?php echo get_the_date('c'); ?&gt;&quot;&gt;&lt;?php echo get_the_date('c'); ?&gt;&lt;/time&gt;
                 &lt;/li&gt;
</pre>
<p>另外我还对 AMP for WP 插件的页脚处理做了点小修改，将页脚上切换到博客首页桌面版本的链接改为切换到当前文章的桌面版本，方便访问者使用。</p>
<h2 id="summary">总结</h2>
<p>对 AMP for WP 插件修改完成之后就可以访问博客的 AMP 版进行验证了，例如我的博客的 AMP 版首页地址就是：</p>
<p><a href="https://zohead.com/?wpamp" target="_blank">https://zohead.com/?wpamp</a></p>
<p>普通用户可以通过安装 Google 推出的 <a href="https://chrome.google.com/webstore/detail/amp-validator/nmoffdblmcmgeicmolmhobpoocbbmknc" target="_blank">AMP Validator</a> 官方 Chrome 扩展检测所访问的 AMP 站点是否配置正确。</p>
<p>网站所有者可以用 Google 搜索的 AMP 在线测试工具进行检测：</p>
<p><a href="https://search.google.com/test/amp" target="_blank">https://search.google.com/test/amp</a></p>
<p>输入要测试的 AMP 版网址就可以开始检测，另外这个测试工具的另一个好处就是检测通过之后可以直接把你的 AMP 站点提交给 Google，让 Google 搜索蜘蛛尽快收录并进行 CDN 缓存。</p>
<p>现在通过 Google 移动端（例如 Android Chrome 浏览器）搜索我的博客，应该就能在搜索结果里看到下面的 AMP 闪电标志了：</p>
<p><img src="http://res.cloudinary.com/digwht2y0/image/upload/v1737371102/google-search-amp.jpg" alt="Google 搜索结果 AMP 标志" title="Google 搜索结果 AMP 标志"></p>
<p>点击搜索结果，你会发现访问的其实是 Google 缓存过的 AMP 地址，下面地址只有移动端浏览器才会显示 AMP 网页：</p>
<p><a href="https://www.google.com/amp/s/zohead.com/%3fwpamp" target="_blank">https://www.google.com/amp/s/zohead.com/%3fwpamp</a></p>
<p>初步启用 AMP 的大体感受就是如果你的梯子还可以，那访问 Google 缓存过的 AMP 网站速度还是非常快的，我这里估计访问 AMP 版网站所需要的流量大概为桌面版本的 1/3。</p>
<p>后面有时间的话还是希望能对 AMP for WP 插件继续改进，例如支持其它的 AMP 后缀或者使用专门的 AMP 子域名方便自己的服务器进行缓存之类的，最后祝大家玩的开心。</p>
]]></content:encoded>
			<wfw:commentRss>https://zohead.com/archives/wordpress-3-amp/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>共同维护公共Google Blocklist的倡议</title>
		<link>https://zohead.com/archives/google-blocklist/</link>
		<comments>https://zohead.com/archives/google-blocklist/#comments</comments>
		<pubDate>Mon, 21 Dec 2015 16:48:40 +0000</pubDate>
		<dc:creator><![CDATA[Uranus Zhou]]></dc:creator>
				<category><![CDATA[Google]]></category>
		<category><![CDATA[网络]]></category>
		<category><![CDATA[Blocklist]]></category>
		<category><![CDATA[Google Drive]]></category>
		<category><![CDATA[Personal Blocklist]]></category>
		<category><![CDATA[倡议]]></category>
		<category><![CDATA[屏蔽]]></category>

		<guid isPermaLink="false">http://zohead.com/?p=1105</guid>
		<description><![CDATA[Google Blocklist介绍 最近在使用 Google 搜索的时候发现搜索一些中文关键字的时候经常出现搜索结果和网站内容不对应的情况，搜索结果描述里看起来和关键字对应，但点开搜索结果看到的网站内容往往是风马牛不相及的垃圾信息，这样明显干扰用户正常搜索结果的行为也算是中文互联网上的一大特色了：SEO过度“优化”（具体可以试试这个关键字：“Y460 驱动”）。 Google 有时会检查搜索结果并做调整，但这样的措施总是跟不上为了利益恶意优化的网站主的，因此 Google 也推出了一款 Personal Blocklist Chrome 浏览器扩展允许用户自行屏蔽掉不需要显示的垃圾搜索结果。 [&#8230;]]]></description>
				<content:encoded><![CDATA[<h2 id="google-blocklist介绍">Google Blocklist介绍</h2>
<p>最近在使用 Google 搜索的时候发现搜索一些中文关键字的时候经常出现搜索结果和网站内容不对应的情况，搜索结果描述里看起来和关键字对应，但点开搜索结果看到的网站内容往往是风马牛不相及的垃圾信息，这样明显干扰用户正常搜索结果的行为也算是中文互联网上的一大特色了：SEO过度“优化”（具体可以试试这个关键字：“Y460 驱动”）。</p>
<p>Google 有时会检查搜索结果并做调整，但这样的措施总是跟不上为了利益恶意优化的网站主的，因此 Google 也推出了一款 <a href="https://chrome.google.com/webstore/detail/nolijncfnkgaikbjbdaogikpmpbdcdef">Personal Blocklist</a> Chrome 浏览器扩展允许用户自行屏蔽掉不需要显示的垃圾搜索结果。</p>
<p>安装完这个扩展之后在 Google 中输入关键字进行搜索后搜索结果下面会显示 “屏蔽 xxx” 的链接，点击就可以将当前搜索结果的网站域名添加到黑名单，之后搜索时默认会自动隐藏这些垃圾站点的搜索结果。另外此扩展会在浏览器工具栏上增加一个按钮，点击会显示当前屏蔽的网站，也可以在这个界面上导入和导出 Blocklist 屏蔽列表，如下图所示：</p>
<p><img src="http://res.cloudinary.com/digwht2y0/image/upload/v1737442872/personal-blocklist.png" alt="Personal Blocklist列表" title="Personal Blocklist列表"></p>
<p>值得一提的是使用 Personal Blocklist 扩展手工屏蔽的网站也会自动提交给 Google 哦，这样也会帮助 Google 改善搜索结果的。</p>
<blockquote>
<p>Personal Blocklist 扩展本身并没有自带基于 Google Drive 之类的云端同步 Blocklist 的功能，不过好在其屏蔽列表也很简单，就是直接的网址列表，我们可以把屏蔽网站列表保存为 Google Drive 文件在不同终端之间同步。</p>
</blockquote>
<h2 id="共同维护倡议">共同维护倡议</h2>
<p>我在 Google Drive 上共享了一份目前自用的 google-block-list.txt 文件，包含我自己添加的屏蔽网站列表，方便给其它用户使用，后面在发现垃圾搜索结果时也会更新这个文件，现在也已经有一百多条记录了，链接如下：</p>
<p><a href="https://drive.google.com/open?id=0B44UqFGcIKJbLThqbzlydnVZaHc">https://drive.google.com/open?id=0B44UqFGcIKJbLThqbzlydnVZaHc</a></p>
<p>另外笔者也深知个人的力量是有限的，如果能像 gfwlist 那样能够有很多用户一起参与更新完善这个列表，这样大家的 Google 搜索结果会更加准确提高效率。</p>
<p>因此：</p>
<ul>
<li>想直接使用这个共享文档？打开链接下载并复制文件内容到 Personal Blocklist 中导入即可，重新进行 Google 搜索就能看到效果；</li>
<li>如果你希望成为此共享文档的编辑者并给其它用户做贡献，欢迎在本博客文章下面评论并附上你的 Google 账户，我将添加为编辑用户；</li>
<li>如果你只是希望在 Blocklist 中临时增加一些站点，欢迎直接访问上面的共享文档链接并直接添加评论附上垃圾站点域名列表；</li>
<li>或者你认为这个文档中的某些网站是被误屏蔽的，也欢迎添加评论指出。</li>
</ul>
<p>当然目前使用 Google 文档进行共享是比较初步的方式，如果需要的话后面也可以换成用 Github 版本库来实现协同编辑提交哦。</p>
<p>祝各位玩的开心，最后来句让人听吐的鸡汤：Let’s make the world a better place。 ^_^</p>
]]></content:encoded>
			<wfw:commentRss>https://zohead.com/archives/google-blocklist/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>WordPress博客增加Google Translate翻译功能</title>
		<link>https://zohead.com/archives/wordpress-google-translate/</link>
		<comments>https://zohead.com/archives/wordpress-google-translate/#comments</comments>
		<pubDate>Fri, 08 Nov 2013 18:23:46 +0000</pubDate>
		<dc:creator><![CDATA[Uranus Zhou]]></dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[技术]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[qTranslate]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[多语言]]></category>
		<category><![CDATA[小工具]]></category>
		<category><![CDATA[插件]]></category>
		<category><![CDATA[翻译]]></category>

		<guid isPermaLink="false">http://zohead.com/?p=623</guid>
		<description><![CDATA[本文同步自（最佳显示效果请点击）：https://zohead.com/archives/wordpress-google-translate/ 之前给 WordPress 博客上安装了 QTranslate 博客以支持多语言，目前本博客已支持中文和英文的了，实际使用时博客作者是需要分别针对中文和英文及其它所需要的语言分别进行翻译处理的，对于笔者这种比较懒的人，除非是老外会看的一些文章，一般也懒的翻译成英文，因此考虑在 WordPress 博客里加上直接使用 Google Translate 进行翻译的处理。 通过查看 Google Translate 提供的接口，我们可以在 WordPres [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>本文同步自（最佳显示效果请点击）：<a href="https://zohead.com/archives/wordpress-google-translate/" target="_blank">https://zohead.com/archives/wordpress-google-translate/</a></p>
<p>之前给 WordPress 博客上安装了 QTranslate 博客以支持多语言，目前本博客已支持中文和英文的了，实际使用时博客作者是需要分别针对中文和英文及其它所需要的语言分别进行翻译处理的，对于笔者这种比较懒的人，除非是老外会看的一些文章，一般也懒的翻译成英文，因此考虑在 WordPress 博客里加上直接使用 Google Translate 进行翻译的处理。</p>
<p>通过查看 Google Translate 提供的接口，我们可以在 WordPress 的仪表盘中的 外观 - 小工具 设置界面中拖动一个 “文本” 类型的小工具到对应的小工具区域中去，小工具标题为 “翻译”，“文本” 类型的小工具可以实现在博客页面的小工具区域中添加自己需要的 HTML 代码，还是比较好用的。</p>
<p>增加的 HTML 代码如下：</p>
<p><pre class="brush: xml; title: ; notranslate">
&lt;div id=&quot;google_translate_element&quot;&gt;&lt;/div&gt;
&lt;script&gt;
function googleTranslateElementInit() {
  new google.translate.TranslateElement({
    pageLanguage: document.documentElement.lang
  }, 'google_translate_element');
}
&lt;/script&gt;
&lt;script src=&quot;http://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit&quot;&gt;&lt;/script&gt;
</pre>
</p>
<p>注意上面代码中的 pageLanguage 表示 WordPress 博客当前的实际语言代码，之前网上看得代码都是写死的，这里我们使用 document.documentElement.lang 动态获取博客当前实际的语言（使用 QTranslate 切换语言时也能正常工作）。</p>
<p>修改保存之后访问主界面就可以看到小工具区域里多了一个 “翻译” 的区域，访客可以直接选择需要翻译到的语言，Google Translate 可以自动翻译当前页面内容为指定语言，实在是非常方便。</p>
<p>接着考虑到有些博主可能像我一样用到了 QTranslate 插件来实现博客多语言，这样就需要修改小工具的标题在不同语言下的显示问题，这时只要把标题改为下面的形式就又可以支持多语言了：</p>
<p>
<pre class="php" style="font-family:monospace;"><span style="color: #009900;">&#91;</span><span style="color: #339933;">:</span>zh<span style="color: #009900;">&#93;</span>翻译<span style="color: #009900;">&#91;</span><span style="color: #339933;">:</span>en<span style="color: #009900;">&#93;</span>Translate</pre>
</p>
<p>上面的形式中将中文和英文字符串写在一起，这样 WordPress 页面在显示时会自动根据当前语言选择应该用的字符串。</p>
<p>另外 Google Translate 界面的样式也是可以定制的，详细请参考 Google Translate 网站翻译页面：</p>
<p><a href="http://translate.google.com/manager/website/" target="_blank">http://translate.google.com/manager/website/</a></p>
]]></content:encoded>
			<wfw:commentRss>https://zohead.com/archives/wordpress-google-translate/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Google街景之对角巷</title>
		<link>https://zohead.com/archives/google-street-diagon-alley/</link>
		<comments>https://zohead.com/archives/google-street-diagon-alley/#comments</comments>
		<pubDate>Mon, 29 Jul 2013 14:09:06 +0000</pubDate>
		<dc:creator><![CDATA[Uranus Zhou]]></dc:creator>
				<category><![CDATA[心情随笔]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[哈利·波特]]></category>
		<category><![CDATA[对角巷]]></category>
		<category><![CDATA[街景]]></category>

		<guid isPermaLink="false">http://zohead.com/?p=458</guid>
		<description><![CDATA[本文同步自（最佳显示效果请点击）：https://zohead.com/archives/google-street-diagon-alley/ 喜欢《Harry Potter》的同学们不可错过的对角巷拍摄地的 Google 街景，对角巷对于熟悉《Harry Potter》迷来说可算是无人不知咯，可能仅次于九又四分之三站台啦。这个实景实际就是 Google 街景车团队花钱在实际生活中的对角巷（就在华纳兄弟工作室）拍摄下的咯。 如下面动态效果所示，可以响应鼠标和键盘动作，鼠标拖动可以转换角度，点击可以前进后退，还可以用滚轮放大缩小，不过建议还是用键盘操作来的顺畅点： 点击 [这里] 可以看看对角 [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>本文同步自（最佳显示效果请点击）：<a href="https://zohead.com/archives/google-street-diagon-alley/" target="_blank">https://zohead.com/archives/google-street-diagon-alley/</a></p>
<p>喜欢《Harry Potter》的同学们不可错过的对角巷拍摄地的 Google 街景，对角巷对于熟悉《Harry Potter》迷来说可算是无人不知咯，可能仅次于九又四分之三站台啦。这个实景实际就是 Google 街景车团队花钱在实际生活中的对角巷（就在华纳兄弟工作室）拍摄下的咯。</p>
<p>如下面动态效果所示，可以响应鼠标和键盘动作，鼠标拖动可以转换角度，点击可以前进后退，还可以用滚轮放大缩小，不过建议还是用键盘操作来的顺畅点：</p>
<p><iframe src="https://maps.google.co.uk/maps?q=Diagon+Alley+at+Warner+Bros.+Studio+Tour+London,+Warner+Bros.+Studio+Tour+London,+Studio+Tour+Drive,+Leavesden&amp;hl=en&amp;sll=51.689718,-0.417566&amp;layer=c&amp;cid=10355248391383225485&amp;panoid=u1gcE6cVKELE_xgImwtVHQ&amp;cbp=13,274.23,,0,0&amp;hq=Diagon+Alley+at+Warner+Bros.+Studio+Tour+London,+Warner+Bros.+Studio+Tour+London,+Studio+Tour+Drive,+Leavesden&amp;t=h&amp;cbll=51.690875,-0.417249&amp;ie=UTF8&amp;hnear=&amp;ll=51.690882,-0.417287&amp;spn=0.004835,0.013411&amp;source=embed&amp;output=svembed" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" width="640" height="550"></iframe></p>
<p>点击 [<a href="https://maps.google.co.uk/maps?q=Diagon+Alley+at+Warner+Bros.+Studio+Tour+London,+Warner+Bros.+Studio+Tour+London,+Studio+Tour+Drive,+Leavesden&amp;amp;hl=en&amp;amp;sll=51.689718,-0.417566&amp;amp;layer=c&amp;amp;cid=10355248391383225485&amp;amp;panoid=u1gcE6cVKELE_xgImwtVHQ&amp;amp;cbp=13,274.23,,0,0&amp;amp;hq=Diagon+Alley+at+Warner+Bros.+Studio+Tour+London,+Warner+Bros.+Studio+Tour+London,+Studio+Tour+Drive,+Leavesden&amp;amp;t=h&amp;amp;cbll=51.690875,-0.417249&amp;amp;ie=UTF8&amp;amp;hnear=&amp;amp;ll=51.690882,-0.417287&amp;amp;spn=0.004835,0.013411&amp;amp;source=embed" target="_blank">这里</a>] 可以看看对角巷的 Google 地图和卫星地图。希望还是哪一天能亲自在这和九又四分之三站台等地感受下气氛咯。 ^_^</p>
]]></content:encoded>
			<wfw:commentRss>https://zohead.com/archives/google-street-diagon-alley/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
