<?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>站趣-分享建站的乐趣教程</title>
	<atom:link href="http://eachsite.org/tag/course/feed/" rel="self" type="application/rss+xml" />
	<link>http://eachsite.org</link>
	<description>站趣致力于一起分享建站的乐趣，并制作各种 WordPress 使用教程、主题以及插件，并关注各种互联网新鲜应用，使国人轻松建站、快乐建站。</description>
	<lastBuildDate>Thu, 29 Mar 2012 08:55:48 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>通过SSH迁移WordPress博客</title>
		<link>http://eachsite.org/transfer-wordpress-via-ssh/</link>
		<comments>http://eachsite.org/transfer-wordpress-via-ssh/#comments</comments>
		<pubDate>Mon, 21 Jun 2010 09:06:35 +0000</pubDate>
		<dc:creator>辐射鱼</dc:creator>
				<category><![CDATA[WordPress 教程]]></category>
		<category><![CDATA[进阶使用]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[教程]]></category>
		<category><![CDATA[空间]]></category>
		<category><![CDATA[站趣]]></category>

		<guid isPermaLink="false">http://eachsite.org/?p=959</guid>
		<description><![CDATA[最近电信抽风，导致电信用户访问host在thePlanet机房的网站很是杯具，无奈我们只得将 imhost.org 2号主机用户暂时迁移到3号主机上避避风头。帮某用户转移数据的时候，发现其数据库相当巨大，有100多M，如果按照传统方法使用PHPMyadmin导出导入的话，估计一天都搞不定。幸好我们的主机都可以开通SSH，如果使用SSH迁移网站的话，导入导出数据库就不会受网速所限，当然，服务器间传输数据的速度也相当之快，一般5～6M/s，遂轻松搞定。
下面我以WordPress为例，演示如何通过SSH迁移WordPress博客：

首先，备份WordPress文件
登陆老主机SSH，进入www网站目录
命令：cd www
把当前目录所有文件以tar命令打包为wp.tar.gz文件
命令：tar -czvf wp.tar.gz *
-c创建
-z用gzip压缩方式
-v显示压缩过程
-f搞成一坨file
备份WordPress数据库
命令：mysqldump -u 数据库用户名 -p 数据库名 > db.sql
转移WordPress文件和数据库到新主机
登陆新主机SSH并进入www目录，使用wget命令从老主机下载WordPress文件和数据库，具体命令如下：
wget yourdomain.com/wp.tar.gz
wget yourdomain.com/db.sql
解压缩 WordPress 文件
tar -xzvf wp.tar.gz
如果是.zip文件可以使用 unzip 命令，不用带参数，相当好记
建立同名、同用户、同密码数据库并导入数据库
进入新主机cPanel建立同名、同用户、同密码数据库，然后在 SSH 里数据以下命令导入数据库：
mysql -u 数据库用户名 -p 数据库名 < db.sql
最后，将域名解析到新IP上
至此，网站转移成功

注意事项：

为了下载方便，请先转移数据后再解析域名到新ip地址；
新数据库名称、用户、密码最好和原数据库保持一致，这样不用再修改wp-config.php文件

其余2号主机用户如果想暂时转移到3号主机上，请将域名、cPanel密码、数据库密码email给我，收到email后我们会为你免费迁移，你到时只需将域名解析到新IP上即可。由此带来的不便，还请见谅。
迎新春庆开张，爱梦科技主机免费送 (9)站趣3号WordPress博客主机上线 (14)站趣2号主机 WordPress 专业空间上线 (42)从A到Z 26条 WordPress .htaccess 技巧 (13)如何使你的博客支持 iPhone (8)如何为 WordPress 文章创建导航目录 (14)自动为 WordPress 文章、Feed 添加版权等信息 (12)如何获取 WordPress 最新置顶文章列表 (12)高亮 WordPress 搜索结果 JQuery 篇 [...]]]></description>
			<content:encoded><![CDATA[<p>最近电信抽风，导致电信用户访问host在thePlanet机房的网站很是杯具，无奈我们只得将 imhost.org <a href="http://eachsite.org/wordpress-host2-plan/">2号主机</a>用户暂时迁移到<a href="http://eachsite.org/3rd-blog-hosting-online/">3号主机</a>上避避风头。帮某用户转移数据的时候，发现其数据库相当巨大，有100多M，如果按照传统方法使用PHPMyadmin导出导入的话，估计一天都搞不定。幸好我们的主机都可以开通SSH，如果使用SSH迁移网站的话，导入导出数据库就不会受网速所限，当然，服务器间传输数据的速度也相当之快，一般5～6M/s，遂轻松搞定。<br />
下面我以WordPress为例，演示<a href="http://eachsite.org/transfer-wordpress-via-ssh/">如何通过SSH迁移WordPress博客</a>：<span id="more-959"></span></p>
<ol>
<li>首先，备份WordPress文件</li>
<p>登陆老主机SSH，进入www网站目录</p>
<blockquote><p>命令：cd www</p></blockquote>
<p>把当前目录所有文件以tar命令打包为wp.tar.gz文件</p>
<blockquote><p>命令：tar -czvf wp.tar.gz *</p></blockquote>
<p>-c创建<br />
-z用gzip压缩方式<br />
-v显示压缩过程<br />
-f搞成一坨file</p>
<li>备份WordPress数据库</li>
<blockquote><p>命令：mysqldump -u 数据库用户名 -p 数据库名 > db.sql</p></blockquote>
<li>转移WordPress文件和数据库到新主机</li>
<p>登陆新主机SSH并进入www目录，使用wget命令从老主机下载WordPress文件和数据库，具体命令如下：</p>
<blockquote><p>wget yourdomain.com/wp.tar.gz<br />
wget yourdomain.com/db.sql</p></blockquote>
<li>解压缩 WordPress 文件</li>
<blockquote><p>tar -xzvf wp.tar.gz</p></blockquote>
<p>如果是.zip文件可以使用 unzip 命令，不用带参数，相当好记</p>
<li>建立同名、同用户、同密码数据库并导入数据库</li>
<p>进入新主机cPanel建立同名、同用户、同密码数据库，然后在 SSH 里数据以下命令导入数据库：</p>
<blockquote><p>mysql -u 数据库用户名 -p 数据库名 < db.sql</p></blockquote>
<li>最后，将域名解析到新IP上</li>
<p>至此，网站转移成功
</ol>
<p>注意事项：</p>
<ol>
<li>为了下载方便，请先转移数据后再解析域名到新ip地址；</li>
<li>新数据库名称、用户、密码最好和原数据库保持一致，这样不用再修改wp-config.php文件</li>
</ol>
<p>其余2号主机用户如果想暂时转移到3号主机上，请将域名、cPanel密码、数据库密码email给我，收到email后我们会为你免费迁移，<strong>你到时只需将域名解析到新IP上即可</strong>。由此带来的不便，还请见谅。</p>
<ul class="related_post"><li><a href="http://eachsite.org/imhost-opening-gift/" title="迎新春庆开张，爱梦科技主机免费送">迎新春庆开张，爱梦科技主机免费送</a> (9)</li><li><a href="http://eachsite.org/3rd-blog-hosting-online/" title="站趣3号WordPress博客主机上线">站趣3号WordPress博客主机上线</a> (14)</li><li><a href="http://eachsite.org/wordpress-host2-plan/" title="站趣2号主机 WordPress 专业空间上线">站趣2号主机 WordPress 专业空间上线</a> (42)</li><li><a href="http://eachsite.org/a-to-z-of-wordpress-htaccess-hacks/" title="从A到Z 26条 WordPress .htaccess 技巧">从A到Z 26条 WordPress .htaccess 技巧</a> (13)</li><li><a href="http://eachsite.org/how-to-create-an-iphone-version-of-your-blog/" title="如何使你的博客支持 iPhone">如何使你的博客支持 iPhone</a> (8)</li><li><a href="http://eachsite.org/how-to-use-menu-in-wp-post/" title="如何为 WordPress 文章创建导航目录">如何为 WordPress 文章创建导航目录</a> (14)</li><li><a href="http://eachsite.org/auto-insert-content-after-each-post/" title="自动为 WordPress 文章、Feed 添加版权等信息">自动为 WordPress 文章、Feed 添加版权等信息</a> (12)</li><li><a href="http://eachsite.org/get-latest-sticky-posts-in-wp/" title="如何获取 WordPress 最新置顶文章列表">如何获取 WordPress 最新置顶文章列表</a> (12)</li><li><a href="http://eachsite.org/highlight-keywords-via-jquery/" title="高亮 WordPress 搜索结果 JQuery 篇">高亮 WordPress 搜索结果 JQuery 篇</a> (14)</li><li><a href="http://eachsite.org/how-to-get-a-particular-sidebar-in-wordpress/" title="WordPress 不同页面、分类调用不同侧边栏详解">WordPress 不同页面、分类调用不同侧边栏详解</a> (9)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://eachsite.org/transfer-wordpress-via-ssh/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>从A到Z 26条 WordPress .htaccess 技巧</title>
		<link>http://eachsite.org/a-to-z-of-wordpress-htaccess-hacks/</link>
		<comments>http://eachsite.org/a-to-z-of-wordpress-htaccess-hacks/#comments</comments>
		<pubDate>Sun, 10 May 2009 02:11:53 +0000</pubDate>
		<dc:creator>辐射鱼</dc:creator>
				<category><![CDATA[WordPress 教程]]></category>
		<category><![CDATA[进阶使用]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[教程]]></category>

		<guid isPermaLink="false">http://eachsite.org/?p=652</guid>
		<description><![CDATA[对于使用 LAMP（Linux+Apache+MySQL+PHP）结构来搭建自己的 WordPress 服务器平台的同学来说，.htaccess 文件再熟悉不过了。合理使用 .htaccess 能极大提高 WordPress 的安全性和易用性。在本篇 WordPress 教程中，我们从A到Z，一起来探讨26条 WordPress .htaccess 技巧。

A：保护 WP- Admin 目录
wp-admin 是 WordPress 管理后台，我们可以限定 IP 访问，不让坏人越雷池一步：

1
2
3
order deny,allow
allow from a.b.c.d # This is your static IP
deny from all

B：Blacklist
绿光荭草小盆友曾非常困惑如何阻止某些 IP 访问其网站，答案就是建立黑名单：

1
2
3
order allow,deny
allow from all
deny from 123.456.789 # Change this IP instead that you want to deny

C：保护 WP-Config 文件
WP-Config 文件里存有数据库地址、用户名以及密码等敏感信息，保护起来吧

1
2
3
4
&#60;files wp-config.php&#62;
order allow,deny
deny [...]]]></description>
			<content:encoded><![CDATA[<p>对于使用 LAMP（Linux+Apache+MySQL+PHP）结构来搭建自己的 WordPress 服务器平台的同学来说，.htaccess 文件再熟悉不过了。合理使用 .htaccess 能极大提高 WordPress 的安全性和易用性。在本篇 WordPress 教程中，我们从A到Z，一起来探讨26条 WordPress .htaccess 技巧。</p>
<ol>
<li><strong>A：保护 WP- Admin 目录</strong></li>
<p>wp-admin 是 WordPress 管理后台，我们可以限定 IP 访问，不让坏人越雷池一步：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">order deny<span style="color: #339933;">,</span>allow
allow from a<span style="color: #339933;">.</span>b<span style="color: #339933;">.</span>c<span style="color: #339933;">.</span>d <span style="color: #666666; font-style: italic;"># This is your static IP
</span>deny from all</pre></td></tr></table></div>

<li><strong>B：Blacklist</strong></li>
<p>绿光荭草小盆友曾非常困惑如何阻止某些 IP 访问其网站，答案就是建立黑名单：<span id="more-652"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">order allow<span style="color: #339933;">,</span>deny
allow from all
deny from 123<span style="color: #339933;">.</span>456<span style="color: #339933;">.</span>789 <span style="color: #666666; font-style: italic;"># Change this IP instead that you want to deny</span></pre></td></tr></table></div>

<li><strong>C：保护 WP-Config 文件</strong></li>
<p>WP-Config 文件里存有数据库地址、用户名以及密码等敏感信息，保护起来吧</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>files wp<span style="color: #339933;">-</span>config<span style="color: #339933;">.</span>php<span style="color: #339933;">&gt;</span>
order allow<span style="color: #339933;">,</span>deny
deny from all
<span style="color: #339933;">&lt;/</span>files<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<li><strong>D：Disable Directory Browsing（禁止列目录）</strong></li>
<p>WordPress 有个安全隐患，就是容易被人列目录，主题、插件目录一目了然，自家的菜园子怎能让人想进就进，想出就出呢，安个门儿吧：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># disable directory browsing
</span>Options All <span style="color: #339933;">-</span>Indexes</pre></td></tr></table></div>

<li><strong>E：Explanation（解释）</strong></li>
<p>都写了4条 .htaccess技巧了，也许还有同学在犯嘀咕，到底什么是 .htaccess 啊？它都能干什么呢？下面我们一起来看看它的解释吧。<br />
.htaccess 文件没有确切的解释，笼统的说 .htaccess 是 Apache 服务器的一个非常强大的分布式配置文件。正确的理解和使用 .htaccess 文件，可以帮助我们优化自己的服务器或者虚拟主机。<br />
启用 .htaccess，需要修改 httpd.conf，启用 AllowOverride，并可以用 AllowOverride 限制特定命令的使用。如果需要使用.htaccess 以外的其他文件名，可以用 AccessFileName 命令来改变。</p>
<li><strong>F：Feedburner</strong></li>
<p>WordPress 自带的 Feed 没有统计功能，我们可以使用 Feedburner 替换它：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>IfModule mod_rewrite<span style="color: #339933;">.</span>c<span style="color: #339933;">&gt;</span>
 RewriteEngine on
 RewriteCond <span style="color: #339933;">%</span><span style="color: #009900;">&#123;</span>HTTP_USER_AGENT<span style="color: #009900;">&#125;</span> <span style="color: #339933;">!</span>FeedBurner    <span style="color: #009900;">&#91;</span>NC<span style="color: #009900;">&#93;</span>
 RewriteCond <span style="color: #339933;">%</span><span style="color: #009900;">&#123;</span>HTTP_USER_AGENT<span style="color: #009900;">&#125;</span> <span style="color: #339933;">!</span>FeedValidator <span style="color: #009900;">&#91;</span>NC<span style="color: #009900;">&#93;</span>
 RewriteRule ^feed<span style="color: #339933;">/</span>?<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span>_0<span style="color: #339933;">-</span>9a<span style="color: #339933;">-</span>z<span style="color: #339933;">-</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #009900;">&#41;</span>?<span style="color: #339933;">/</span>?$ http<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//feedproxy.google.com/yourfeedburnerid [R=302,NC,L]</span>
<span style="color: #339933;">&lt;/</span>IfModule<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>当然，如果你能不介意 Feedsky 的抓取速度的话，国内的朋友可以使用 Feedsky 替换</p>
<li><strong>G：Gzip 压缩 js 和 css</strong></li>
<p>许多 WordPress 教程都提及如何使用 Gzip 压缩问题，可传统的 Gzip 压缩会耗费一定的 CPU 资源，当 CPU 使用率过高时，Gzip 压缩模式下的网页访问速度可能会更慢。我们可以使用 gzip 将 js 和 css 文件压缩成 .gz 压缩文件，就能很好解决流量、访问速度和服务器 CPU 资源的矛盾问题。</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">RewriteRule <span style="color: #009900;">&#40;</span><span style="color: #339933;">.*.</span>css$<span style="color: #339933;">|.*.</span>js$<span style="color: #009900;">&#41;</span> gzip<span style="color: #339933;">.</span>php?$<span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#91;</span>L<span style="color: #009900;">&#93;</span></pre></div></div>

<p>点击这里下载 <strong><a href="http://wopus.googlecode.com/files/gzip.php">gzip.php</a></strong> 文件</p>
<li><strong>H：Disable hotlinking（防止盗链）</strong></li>
<p>盗链是指别人直接链接你站内资源，比如图片、音乐、电子书等文件，从而浪费网站宝贵的流量，我们可以使用以下 .htaccess 技巧阻止盗链：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">RewriteEngine on
RewriteCond <span style="color: #339933;">%</span><span style="color: #009900;">&#123;</span>HTTP_REFERER<span style="color: #009900;">&#125;</span> <span style="color: #339933;">!</span>^$
RewriteCond <span style="color: #339933;">%</span><span style="color: #009900;">&#123;</span>HTTP_REFERER<span style="color: #009900;">&#125;</span> <span style="color: #339933;">!</span>^http<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//(www\.)?yourdomain.com/.*$ [NC]</span>
<span style="color: #666666; font-style: italic;">#RewriteRule \.(gif|jpg)$ - [F]
</span>RewriteRule \<span style="color: #339933;">.</span><span style="color: #009900;">&#40;</span>gif<span style="color: #339933;">|</span>jpg<span style="color: #009900;">&#41;</span>$ http<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//www.yourdomain.com/nohotlink.gif [R,L]</span></pre></td></tr></table></div>

<p>注：替换 yourdomain.com 为自己的网址和 http://www.yourdomain.com/nohotlink.gif 为自己定制的防盗链声明图片</p>
<li><strong>I：Important（重要性）!</strong></li>
<p>看了前面几条 .htaccess 技巧，你是不是蠢蠢欲动、跃跃欲试了呢？！别急，先备份，时常备份才能免除后顾之忧。</p>
<li><strong>J：Jauntily show the admin’s email address in error message</strong></li>
<p>在错误页显示管理员邮箱，以使访问者能及时联系我们。<br />
ServerAdmin name@domain.com</p>
<li><strong>K：Keep RSS ‘content thieves’ away（防止 RSS 采集）</strong></li>
<p>我们有很多方法防止垃圾站点采集，可通过 RSS 采集，总是令人防不胜防，幸好，我们还可以通过 .htaccess 技巧，阻止其采集我们的网站内容，只要知道它的 IP 即可。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">RewriteEngine on
 RewriteCond <span style="color: #339933;">%</span><span style="color: #009900;">&#123;</span>REMOTE_ADDR<span style="color: #009900;">&#125;</span> ^123<span style="color: #339933;">.</span>45<span style="color: #339933;">.</span>67<span style="color: #339933;">.</span>89
 RewriteRule ^<span style="color: #009900;">&#40;</span><span style="color: #339933;">.*</span><span style="color: #009900;">&#41;</span>$ http<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//yourdomain.com/feed</span></pre></td></tr></table></div>

<li><strong>L：Limiting number of simultaneous connections（限制并发连接数）</strong></li>
<p>过高的并发连接数会严重影响服务器性能，我们可以通过设置 .htaccess 适当限制一下，如：<br />
MaxClients 40</p>
<li><strong>M：Maintenance（维护页面）</strong></li>
<p>当我们的站点正在升级、迁移时，我们需要做一个维护页面：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">RewriteEngine on
RewriteCond <span style="color: #339933;">%</span><span style="color: #009900;">&#123;</span>REQUEST_URI<span style="color: #009900;">&#125;</span> <span style="color: #339933;">!/</span>maintenance<span style="color: #339933;">.</span>html$
RewriteCond <span style="color: #339933;">%</span><span style="color: #009900;">&#123;</span>REMOTE_ADDR<span style="color: #009900;">&#125;</span> <span style="color: #339933;">!</span>^<span style="color: #cc66cc;">123</span>\<span style="color:#800080;">.123</span>\<span style="color:#800080;">.123</span>\<span style="color:#800080;">.123</span>
RewriteRule $ <span style="color: #339933;">/</span>maintenance<span style="color: #339933;">.</span>html <span style="color: #009900;">&#91;</span>R<span style="color: #339933;">=</span><span style="color: #cc66cc;">302</span><span style="color: #339933;">,</span>L<span style="color: #009900;">&#93;</span></pre></td></tr></table></div>

<p>注：新建一个 maintenance.html 页面，并将 123.123.123.123 替换成你自己的 IP 地址</p>
<li><strong>N：Deny no referer requests</strong></li>
<p>通过机器人群发垃圾留言是 Spammers 的惯用伎俩，下面这条 .htaccess 技巧将判断评论提交地址，如非本站，则拒绝：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">RewriteEngine On
RewriteCond <span style="color: #339933;">%</span><span style="color: #009900;">&#123;</span>REQUEST_METHOD<span style="color: #009900;">&#125;</span> POST
RewriteCond <span style="color: #339933;">%</span><span style="color: #009900;">&#123;</span>REQUEST_URI<span style="color: #009900;">&#125;</span> <span style="color: #339933;">.</span>wp<span style="color: #339933;">-</span>comments<span style="color: #339933;">-</span>post\<span style="color: #339933;">.</span>php<span style="color: #339933;">*</span>
RewriteCond <span style="color: #339933;">%</span><span style="color: #009900;">&#123;</span>HTTP_REFERER<span style="color: #009900;">&#125;</span> <span style="color: #339933;">!.*</span>yourblog<span style="color: #339933;">.</span>com<span style="color: #339933;">.*</span> <span style="color: #009900;">&#91;</span>OR<span style="color: #009900;">&#93;</span>
RewriteCond <span style="color: #339933;">%</span><span style="color: #009900;">&#123;</span>HTTP_USER_AGENT<span style="color: #009900;">&#125;</span> ^$
RewriteRule <span style="color: #009900;">&#40;</span><span style="color: #339933;">.*</span><span style="color: #009900;">&#41;</span> ^http<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//%{REMOTE_ADDR}/$ [R=301,L]</span></pre></td></tr></table></div>

<li><strong>O：Force files when opening to ’save as’</strong></li>
<p>如果你经常提供 .avi .mpg .mov 等媒体文件下载，下面这条 .htaccess 非常有用，它将强迫保存文件而不是在线播放。</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">AddType application<span style="color: #339933;">/</span>octet<span style="color: #339933;">-</span>stream <span style="color: #339933;">.</span>avi <span style="color: #339933;">.</span>mpg <span style="color: #339933;">.</span>mov <span style="color: #339933;">.</span>pdf <span style="color: #339933;">.</span>xls <span style="color: #339933;">.</span>mp4</pre></div></div>

<li><strong>P：Protect your .htaccess file（保护 .htaccess 文件）</strong></li>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>Files ~ <span style="color: #0000ff;">&quot;^.*\.([Hh][Tt][Aa])&quot;</span><span style="color: #339933;">&gt;</span>
order allow<span style="color: #339933;">,</span>deny
deny from all
satisfy all
<span style="color: #339933;">&lt;/</span>Files<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<li><strong>Q：Quicken your site’s loading time by caching</strong></li>
<p>又是一条通过 gzip 压缩减少页面加载时间的 .htaccess 技巧，文章太长，请点击 <a href="http://www.samaxes.com/2008/04/20/htaccess-gzip-and-cache-your-site-for-faster-loading-and-bandwidth-saving/">.htaccess-gazip and cache your site for faster loading and bandwidth saving</a> 查看</p>
<li><strong>R:Redirect to other pages on your site（重定向博客地址）</strong></li>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">RedirectMatch <span style="color: #cc66cc;">301</span> ^<span style="color: #339933;">/</span>blog<span style="color: #339933;">/.*</span>$ http<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//domain.com/target.html</span></pre></td></tr></table></div>

<li><strong>S：Spam</strong></li>
<p>阻止 spammers、scrapers 以及其他 scumbags 是我们义不容辞的任务，这不，就有人建立了一个 <a href="http://perishablepress.com/press/2007/06/28/ultimate-htaccess-blacklist/">.htaccess 黑名单</a>（实时更新）</p>
<li><strong>T：Set the timezone of the server（设置服务器时区）</strong></li>
<p>SetEnv TZ America/Indianapolis<br />
请将 America/Indianapolis 设置为大家所在时区即可，时区的列表可以在这里找到: <a href=" http://us2.php.net/manual/en/timezones.php">http://us2.php.net/manual/en/timezones.php</a></p>
<li><strong>U：Remove /category/ from your category URL</strong></li>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">RedirectMatch <span style="color: #cc66cc;">301</span> ^<span style="color: #339933;">/</span>category<span style="color: #339933;">/</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">.+</span><span style="color: #009900;">&#41;</span>$ http<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//domain.com/$1</span>
<span style="color: #666666; font-style: italic;"># OR
</span>RewriteRule ^category<span style="color: #339933;">/</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">.+</span><span style="color: #009900;">&#41;</span>$ http<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//domain.com/$1 [R=301,L]</span></pre></td></tr></table></div>

<li><strong>V：Valiantly automatically fix URL spelling mistakes</strong></li>
<p>这个 .htaccess 小把戏将为大家自动修正 url 拼写错误：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>IfModule mod_speling<span style="color: #339933;">.</span>c<span style="color: #339933;">&gt;</span>
 CheckSpelling On
 <span style="color: #339933;">&lt;/</span>IfModule<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<li><strong>W：Redirect from http://www.whatever to http://whatever</strong></li>
<p>也许许多同学像站趣一样爱用不带 www 的 url 地址，那么，如果有习惯性输入 www 的访客怎么办？通过 .htaccess 将其重定向过来呗：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># permanently redirect from www domain to non-www domain
</span>RewriteEngine on
Options <span style="color: #339933;">+</span>FollowSymLinks
RewriteCond <span style="color: #339933;">%</span><span style="color: #009900;">&#123;</span>HTTP_HOST<span style="color: #009900;">&#125;</span> ^www\<span style="color: #339933;">.</span>domain\<span style="color: #339933;">.</span>tld$ <span style="color: #009900;">&#91;</span>NC<span style="color: #009900;">&#93;</span>
RewriteRule ^<span style="color: #009900;">&#40;</span><span style="color: #339933;">.*</span><span style="color: #009900;">&#41;</span>$ http<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//domain.tld/$1 [R=301,L]</span></pre></td></tr></table></div>

<li><strong>X：Make your wp-login.php page xenophobic</strong></li>
<p>wp-login.php 是 WordPress 的登录页面，阻止其他人登录，不就相当于保护了 WordPress 管理后台了么：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>Files wp<span style="color: #339933;">-</span>login<span style="color: #339933;">.</span>php<span style="color: #339933;">&gt;</span>
 Order deny<span style="color: #339933;">,</span>allow
 Deny from All
 Allow from 123<span style="color: #339933;">.</span>456<span style="color: #339933;">.</span>789<span style="color: #339933;">.</span>0
 <span style="color: #339933;">&lt;/</span>Files<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<li><strong>Y：Easily rename your .htaccess file（重命名 .htaccess）</strong></li>
<p>我们可以将 .htaccess 命名为任意文件名，以达到保护其安全性的目的：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># rename htaccess files
</span>AccessFileName ht<span style="color: #339933;">.</span>access</pre></td></tr></table></div>

<li><strong>Z：Say zygote in your .htaccess file</strong></li>
<p>这真是一个很雷人的 .htaccess 技巧，当我们在 .htaccess 加入 zygote 时，留言者留言时则需在留言开头添加“#”，囧
</ol>
<p>原文地址：<a href="http://www.nometech.com/blog/a-to-z-of-wordpress-htaccess-hacks/">A to Z of WordPress .htaccess Hacks</a><br />
站趣译文：<a href="http://eachsite.org/a-to-z-of-wordpress-htaccess-hacks/">从A到Z 26条 WordPress .htaccess 技巧</a>（有改动）</p>
<ul class="related_post"><li><a href="http://eachsite.org/transfer-wordpress-via-ssh/" title="通过SSH迁移WordPress博客">通过SSH迁移WordPress博客</a> (13)</li><li><a href="http://eachsite.org/how-to-create-an-iphone-version-of-your-blog/" title="如何使你的博客支持 iPhone">如何使你的博客支持 iPhone</a> (8)</li><li><a href="http://eachsite.org/how-to-use-menu-in-wp-post/" title="如何为 WordPress 文章创建导航目录">如何为 WordPress 文章创建导航目录</a> (14)</li><li><a href="http://eachsite.org/auto-insert-content-after-each-post/" title="自动为 WordPress 文章、Feed 添加版权等信息">自动为 WordPress 文章、Feed 添加版权等信息</a> (12)</li><li><a href="http://eachsite.org/get-latest-sticky-posts-in-wp/" title="如何获取 WordPress 最新置顶文章列表">如何获取 WordPress 最新置顶文章列表</a> (12)</li><li><a href="http://eachsite.org/highlight-keywords-via-jquery/" title="高亮 WordPress 搜索结果 JQuery 篇">高亮 WordPress 搜索结果 JQuery 篇</a> (14)</li><li><a href="http://eachsite.org/how-to-get-a-particular-sidebar-in-wordpress/" title="WordPress 不同页面、分类调用不同侧边栏详解">WordPress 不同页面、分类调用不同侧边栏详解</a> (9)</li><li><a href="http://eachsite.org/wp-page-menu/" title="wp_page_menu 函数使用详解">wp_page_menu 函数使用详解</a> (3)</li><li><a href="http://eachsite.org/use-getavatar-to-add-gravatar-in-wp/" title="使用 get_avatar 为 WP 自定义 Gravatar 默认头像">使用 get_avatar 为 WP 自定义 Gravatar 默认头像</a> (22)</li><li><a href="http://eachsite.org/add-a-default-gravatar-in-wordpress/" title="如何在 WordPress 中添加 Gravatar 默认头像">如何在 WordPress 中添加 Gravatar 默认头像</a> (11)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://eachsite.org/a-to-z-of-wordpress-htaccess-hacks/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>如何使你的博客支持 iPhone</title>
		<link>http://eachsite.org/how-to-create-an-iphone-version-of-your-blog/</link>
		<comments>http://eachsite.org/how-to-create-an-iphone-version-of-your-blog/#comments</comments>
		<pubDate>Mon, 04 May 2009 02:07:50 +0000</pubDate>
		<dc:creator>辐射鱼</dc:creator>
				<category><![CDATA[WordPress 插件]]></category>
		<category><![CDATA[插件推荐]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[主题]]></category>
		<category><![CDATA[插件]]></category>
		<category><![CDATA[教程]]></category>

		<guid isPermaLink="false">http://eachsite.org/?p=558</guid>
		<description><![CDATA[iPhone 无疑是时下最热门的手机客户端，那我们的 WordPress 博客如何不支持它呢？今天，辐射鱼为大家介绍一款既是 WordPress 插件，又是 WordPress 主题的东东，使各位的 WordPress 博客适合 iPhone 和 iTouch 用户访问。启用它以后，如果访客使用 iPhone 或 iTouch 访问我们的 WordPress 博客时，会自动生成一个特殊的、为 iPhone 或 iTouch 优化过的主题，而对于其他访问者，则还是你原来的主题。

插件功能：

优化 iPhone 或 iTouch 用户体验
自动识别 iPhone 或 iTouch 访客，并为其显示优化过的主题
自动缩小图片至300px以适合 iPhone 或 iTouch
自带 Simple iPhone/iPod-like theme
版本要求：WordPress 2.0.4 &#8211; 2.5
插件版本：Version 0.1.2
插件、主题地址：iWPhone WordPress Plugin and Theme
下载地址：iWPhone WordPress Plugin and Theme

安装方法：
习惯了只安装 WordPress 主题和插件，是不是对这个既是主题又是插件的东东感到很好奇呢？！iWPhone WordPress Plugin and [...]]]></description>
			<content:encoded><![CDATA[<p>iPhone 无疑是时下最热门的手机客户端，那我们的 WordPress 博客如何不支持它呢？今天，辐射鱼为大家介绍一款既是 <a href="http://eachsite.org/category/wordpress-plugins/plugins-intro/">WordPress 插件</a>，又是 <a href="http://eachsite.org/category/wordpress-themes/themes-intro/">WordPress 主题</a>的东东，使各位的 WordPress 博客适合 iPhone 和 iTouch 用户访问。启用它以后，如果访客使用 iPhone 或 iTouch 访问我们的 WordPress 博客时，会自动生成一个特殊的、为 iPhone 或 iTouch 优化过的主题，而对于其他访问者，则还是你原来的主题。<br />
<img src="http://eachsite.org/wp-content/eachsite/2009/05/iwphone_on_iphone.jpg" alt="WordPress iphone 主题、插件 iwphone" title="WordPress iphone 主题、插件 iwphone" width="144" height="260" class="aligncenter size-full wp-image-559" /><br />
<strong>插件功能：</strong><span id="more-558"></span></p>
<ol>
<li>优化 iPhone 或 iTouch 用户体验</li>
<li>自动识别 iPhone 或 iTouch 访客，并为其显示优化过的主题</li>
<li>自动缩小图片至300px以适合 iPhone 或 iTouch</li>
<li>自带 Simple iPhone/iPod-like theme</li>
<li>版本要求：WordPress 2.0.4 &#8211; 2.5</li>
<li>插件版本：Version 0.1.2</li>
<li>插件、主题地址：<a href="http://iwphone.contentrobot.com/2007/07/04/iwphone-wordpress-plugin-and-theme/">iWPhone WordPress Plugin and Theme</a></li>
<li>下载地址：<a href="http://iwphone.contentrobot.com/download-manager.php?id=6">iWPhone WordPress Plugin and Theme</a></li>
</ol>
<p><strong>安装方法：</strong><br />
习惯了只安装 WordPress 主题和插件，是不是对这个既是主题又是插件的东东感到很好奇呢？！iWPhone WordPress Plugin and Theme 的安装方法也很简单：</p>
<ol>
<li>将 “iwphone-by-contentrobot” 文件夹下的 <strong>“iwphone.php”</strong> 文件上传至 WordPress 插件目录，先不忙激活</li>
<li>将 <strong>“iwphone-by-contentrobot”</strong> 文件夹内所有文件上传至 WordPress 主题目录，千万不要将该主题（也就是 <strong>iWPhone-by-ContentRobot</strong>）激活</li>
<li>进入 WordPress 管理后台激活 <strong>iWPhone</strong>插件</li>
</ol>
<p>现在，使用 iPhone 或 iTouch 访问你的 WordPress 博客，界面是不是和使用 PC 看到的不一样呢？！</p>
<ul class="related_post"><li><a href="http://eachsite.org/safest-way-to-include-plugin-code-in-themes/" title="在 WordPress 主题中安全的调用插件代码">在 WordPress 主题中安全的调用插件代码</a> (0)</li><li><a href="http://eachsite.org/use-getavatar-to-add-gravatar-in-wp/" title="使用 get_avatar 为 WP 自定义 Gravatar 默认头像">使用 get_avatar 为 WP 自定义 Gravatar 默认头像</a> (22)</li><li><a href="http://eachsite.org/add-a-default-gravatar-in-wordpress/" title="如何在 WordPress 中添加 Gravatar 默认头像">如何在 WordPress 中添加 Gravatar 默认头像</a> (11)</li><li><a href="http://eachsite.org/show-wordpress-category-images/" title="WordPress CMS 主题技巧：显示 WordPress 分类图片">WordPress CMS 主题技巧：显示 WordPress 分类图片</a> (9)</li><li><a href="http://eachsite.org/wordpress-cms-tips-latest-posts-by-cat/" title="WordPress CMS 技巧：按照分类调用最新文章">WordPress CMS 技巧：按照分类调用最新文章</a> (26)</li><li><a href="http://eachsite.org/wordpress-shortcodes/" title="精通 WordPress 短代码">精通 WordPress 短代码</a> (6)</li><li><a href="http://eachsite.org/wordpress-post-images-tips/" title="自动获取 WordPress 缩略图增强应用">自动获取 WordPress 缩略图增强应用</a> (5)</li><li><a href="http://eachsite.org/get-1st-images-in-wordpress/" title="自动获取 WordPress 缩略图">自动获取 WordPress 缩略图</a> (12)</li><li><a href="http://eachsite.org/wordpress27-threading-comments/" title="WordPress2.7 嵌套评论">WordPress2.7 嵌套评论</a> (7)</li><li><a href="http://eachsite.org/enhance-theme-suit-wordpress27/" title="如何使你的主题兼容 WordPress2.7">如何使你的主题兼容 WordPress2.7</a> (9)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://eachsite.org/how-to-create-an-iphone-version-of-your-blog/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>如何为 WordPress 文章创建导航目录</title>
		<link>http://eachsite.org/how-to-use-menu-in-wp-post/</link>
		<comments>http://eachsite.org/how-to-use-menu-in-wp-post/#comments</comments>
		<pubDate>Thu, 23 Apr 2009 02:36:44 +0000</pubDate>
		<dc:creator>辐射鱼</dc:creator>
				<category><![CDATA[WordPress 教程]]></category>
		<category><![CDATA[新手入门]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[教程]]></category>

		<guid isPermaLink="false">http://eachsite.org/?p=540</guid>
		<description><![CDATA[当我们要写的材料很长很长时，你是否迫切需要一个类似图书目录的东东呢？对，这个东东就是本文要讲的锚链接！！！我在 wp_page_menu 函数使用详解这篇文章中就创建了几个锚链接，大家可以先看看演示。
什么是锚链接？
我们知道，链接是一个网站中指向其它资源的部分，其它资源包括其它 HTML 文档、文本文件、PDF 等。链接又包括两类：
①	通过使用 link 元素创建的链接，浏览器会自动导入。这类链接我们通常会在 WordPress 主题的 header.php 文件中见到

&#60;link rel=&#34;stylesheet&#34; href=&#34;styles.css&#34;&#62;

②	另一类则是用户可选择去激活的链接，被称为 anchors（锚），我们可以通过使用 a 元素把锚加入文档。
锚元素具有以下几个可用属性：

    * href 属性：锚指向的资源（外部文件或一个锚 ID）。
    * id 属性：如果锚被充当一个目标，而不是一个链接时，使用锚 ID。
    * title 属性：锚所指向外部资源的附加信息。

好了，P话不多说了，切入正题，下面我们就来讲讲如何利用锚链接为 WordPress 文章创建导航目录吧，只需要两段简单的 HTML 代码：
①	创建导航目录
为 herf 属性加上 &#8216;#锚 ID&#8217; 即可，如：

1
2
3
4
	&#60;a href=&#34;#primary&#34;&#62;WordPress 页面多级菜单&#60;/a&#62;
	&#60;a href=&#34;#subtitle&#34;&#62;WordPress 页面副标题&#60;/a&#62;
	&#60;a href=&#34;#class&#34;&#62;WordPress 页面链接分类&#60;/a&#62;
	&#60;a href=&#34;#dynamic&#34;&#62;WordPress 动态菜单&#60;/a&#62;

②	指向导航目录
为每段文章增加一个导航标题，使导航目录能指向正确位置，如：

1
2
3
4
	&#60;a id=&#34;#primary&#34;&#62;WordPress [...]]]></description>
			<content:encoded><![CDATA[<p>当我们要写的材料很长很长时，你是否迫切需要一个类似图书目录的东东呢？对，这个东东就是本文要讲的锚链接！！！我在 <a href="http://eachsite.org/wp-page-menu/">wp_page_menu 函数使用详解</a>这篇文章中就创建了几个锚链接，大家可以先看看演示。<br />
<strong>什么是锚链接？</strong><br />
我们知道，链接是一个网站中指向其它资源的部分，其它资源包括其它 HTML 文档、文本文件、PDF 等。链接又包括两类：<br />
①	通过使用 link 元素创建的链接，浏览器会自动导入。这类链接我们通常会在 <a href="http://eachsite.org/category/wordpress-themes/themes-intro/">WordPress 主题</a>的 header.php 文件中见到</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">&lt;link rel<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;stylesheet&quot;</span> href<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;styles.css&quot;</span><span style="color: #00AA00;">&gt;</span></pre></div></div>

<p>②	另一类则是用户可选择去激活的链接，被称为 anchors（锚），我们可以通过使用 a 元素把锚加入文档。<br />
<strong>锚元素具有以下几个可用属性：</strong></p>
<blockquote><p>
    * href 属性：锚指向的资源（外部文件或一个锚 ID）。<br />
    * id 属性：如果锚被充当一个目标，而不是一个链接时，使用锚 ID。<br />
    * title 属性：锚所指向外部资源的附加信息。
</p></blockquote>
<p>好了，P话不多说了，切入正题，下面我们就来讲讲如何利用锚链接为 WordPress 文章创建导航目录吧，只需要两段简单的 HTML 代码：<span id="more-540"></span><br />
①	创建导航目录<br />
为 herf 属性加上 <strong>&#8216;#锚 ID&#8217;</strong> 即可，如：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">	&lt;a href=&quot;#primary&quot;&gt;WordPress 页面多级菜单&lt;/a&gt;
	&lt;a href=&quot;#subtitle&quot;&gt;WordPress 页面副标题&lt;/a&gt;
	&lt;a href=&quot;#class&quot;&gt;WordPress 页面链接分类&lt;/a&gt;
	&lt;a href=&quot;#dynamic&quot;&gt;WordPress 动态菜单&lt;/a&gt;</pre></td></tr></table></div>

<p>②	指向导航目录<br />
为每段文章增加一个导航标题，使导航目录能指向正确位置，如：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">	&lt;a id=&quot;#primary&quot;&gt;WordPress 页面多级菜单&lt;/a&gt;
	&lt;a id=&quot;#subtitle&quot;&gt;WordPress 页面副标题&lt;/a&gt;
	&lt;a id=&quot;#class&quot;&gt;WordPress 页面链接分类&lt;/a&gt;
	&lt;a id=&quot;#dynamic&quot;&gt;WordPress 动态菜单&lt;/a&gt;</pre></td></tr></table></div>

<p>经过上面简单的两步，一个同一业内的导航目录就添加成功了，如果我们想在其他页面引用这个导航目录，只需要在 href 属性中加上页面 URL 地址就可以了，即：</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;a href=″URL＃id″&gt;....&lt;/a&gt;</pre></div></div>

<p>当然，这个导航目录可以用于任何地方，并不仅限于 <a href="http://eachsite.org/tag/wordpress/">WordPress</a>，如果你还有其他好的想法，欢迎向<a href="http://eachsite.org/" title="站趣-分享建站的乐趣" alt="站趣-分享建站的乐趣">站趣-分享建站的乐趣</a>反馈。</p>
<ul class="related_post"><li><a href="http://eachsite.org/transfer-wordpress-via-ssh/" title="通过SSH迁移WordPress博客">通过SSH迁移WordPress博客</a> (13)</li><li><a href="http://eachsite.org/a-to-z-of-wordpress-htaccess-hacks/" title="从A到Z 26条 WordPress .htaccess 技巧">从A到Z 26条 WordPress .htaccess 技巧</a> (13)</li><li><a href="http://eachsite.org/how-to-create-an-iphone-version-of-your-blog/" title="如何使你的博客支持 iPhone">如何使你的博客支持 iPhone</a> (8)</li><li><a href="http://eachsite.org/auto-insert-content-after-each-post/" title="自动为 WordPress 文章、Feed 添加版权等信息">自动为 WordPress 文章、Feed 添加版权等信息</a> (12)</li><li><a href="http://eachsite.org/get-latest-sticky-posts-in-wp/" title="如何获取 WordPress 最新置顶文章列表">如何获取 WordPress 最新置顶文章列表</a> (12)</li><li><a href="http://eachsite.org/highlight-keywords-via-jquery/" title="高亮 WordPress 搜索结果 JQuery 篇">高亮 WordPress 搜索结果 JQuery 篇</a> (14)</li><li><a href="http://eachsite.org/how-to-get-a-particular-sidebar-in-wordpress/" title="WordPress 不同页面、分类调用不同侧边栏详解">WordPress 不同页面、分类调用不同侧边栏详解</a> (9)</li><li><a href="http://eachsite.org/wp-page-menu/" title="wp_page_menu 函数使用详解">wp_page_menu 函数使用详解</a> (3)</li><li><a href="http://eachsite.org/use-getavatar-to-add-gravatar-in-wp/" title="使用 get_avatar 为 WP 自定义 Gravatar 默认头像">使用 get_avatar 为 WP 自定义 Gravatar 默认头像</a> (22)</li><li><a href="http://eachsite.org/add-a-default-gravatar-in-wordpress/" title="如何在 WordPress 中添加 Gravatar 默认头像">如何在 WordPress 中添加 Gravatar 默认头像</a> (11)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://eachsite.org/how-to-use-menu-in-wp-post/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>自动为 WordPress 文章、Feed 添加版权等信息</title>
		<link>http://eachsite.org/auto-insert-content-after-each-post/</link>
		<comments>http://eachsite.org/auto-insert-content-after-each-post/#comments</comments>
		<pubDate>Fri, 17 Apr 2009 00:19:04 +0000</pubDate>
		<dc:creator>辐射鱼</dc:creator>
				<category><![CDATA[WordPress 教程]]></category>
		<category><![CDATA[新手入门]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[教程]]></category>

		<guid isPermaLink="false">http://eachsite.org/?p=523</guid>
		<description><![CDATA[也许，许多同学早已通过修改 WordPress 主题目录下的 single.php 文件以及使用插件的方法为 WordPress 文章、Feed 添加了版权等信息，本文当然不是炒冷饭，而是有了新方法，使用 WordPress 自定义函数以及 add_filter 钩子，自动向 WordPress 内容里添加版权等信息，当然，大家也可以将其替换成广告：）这听起来是不是稍显复杂，其实代码很简单，不信请往下看：
老一套，粘贴以下代码到 functions.php：

1
2
3
4
5
6
7
8
9
10
function insertNote&#40;$content&#41; &#123;
        if&#40;!is_feed&#40;&#41; &#38;&#38; !is_home&#40;&#41;&#41; &#123;
                $content.= &#34;&#60;div class='sub'&#62;&#34;;
          [...]]]></description>
			<content:encoded><![CDATA[<p>也许，许多同学早已通过修改 <a href="http://eachsite.org/category/wordpress-themes/themes-intro/">WordPress 主题</a>目录下的 single.php 文件以及使用插件的方法为 <a href="http://eachsite.org/tag/wordpress/">WordPress</a> 文章、Feed 添加了版权等信息，本文当然不是炒冷饭，而是有了新方法，使用 WordPress 自定义函数以及 add_filter 钩子，自动向 WordPress 内容里添加版权等信息，当然，大家也可以将其替换成广告：）这听起来是不是稍显复杂，其实代码很简单，不信请往下看：<br />
老一套，粘贴以下代码到 functions.php：<span id="more-523"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> insertNote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>is_feed<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span>is_home<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$content</span><span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;div class='sub'&gt;&quot;</span><span style="color: #339933;">;</span>
                <span style="color: #000088;">$content</span><span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;h4&gt;喜欢这篇文章吗?&lt;/h4&gt;&quot;</span><span style="color: #339933;">;</span>
                <span style="color: #000088;">$content</span><span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;p&gt;请订阅本站  &lt;a href='http://eachsite.org/feed'&gt;RSS feed&lt;/a&gt; ,站趣-分享建站的乐趣版权所有!&lt;/p&gt;&quot;</span><span style="color: #339933;">;</span>
                <span style="color: #000088;">$content</span><span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;/div&gt;&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$content</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
add_filter <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'the_content'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'insertNote'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>怎么样，够简单吧？！至于 CSS 样式，大家根据自身需要定义吧，我就不献丑了。</p>
<ul class="related_post"><li><a href="http://eachsite.org/transfer-wordpress-via-ssh/" title="通过SSH迁移WordPress博客">通过SSH迁移WordPress博客</a> (13)</li><li><a href="http://eachsite.org/a-to-z-of-wordpress-htaccess-hacks/" title="从A到Z 26条 WordPress .htaccess 技巧">从A到Z 26条 WordPress .htaccess 技巧</a> (13)</li><li><a href="http://eachsite.org/how-to-create-an-iphone-version-of-your-blog/" title="如何使你的博客支持 iPhone">如何使你的博客支持 iPhone</a> (8)</li><li><a href="http://eachsite.org/how-to-use-menu-in-wp-post/" title="如何为 WordPress 文章创建导航目录">如何为 WordPress 文章创建导航目录</a> (14)</li><li><a href="http://eachsite.org/get-latest-sticky-posts-in-wp/" title="如何获取 WordPress 最新置顶文章列表">如何获取 WordPress 最新置顶文章列表</a> (12)</li><li><a href="http://eachsite.org/highlight-keywords-via-jquery/" title="高亮 WordPress 搜索结果 JQuery 篇">高亮 WordPress 搜索结果 JQuery 篇</a> (14)</li><li><a href="http://eachsite.org/how-to-get-a-particular-sidebar-in-wordpress/" title="WordPress 不同页面、分类调用不同侧边栏详解">WordPress 不同页面、分类调用不同侧边栏详解</a> (9)</li><li><a href="http://eachsite.org/wp-page-menu/" title="wp_page_menu 函数使用详解">wp_page_menu 函数使用详解</a> (3)</li><li><a href="http://eachsite.org/use-getavatar-to-add-gravatar-in-wp/" title="使用 get_avatar 为 WP 自定义 Gravatar 默认头像">使用 get_avatar 为 WP 自定义 Gravatar 默认头像</a> (22)</li><li><a href="http://eachsite.org/add-a-default-gravatar-in-wordpress/" title="如何在 WordPress 中添加 Gravatar 默认头像">如何在 WordPress 中添加 Gravatar 默认头像</a> (11)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://eachsite.org/auto-insert-content-after-each-post/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>如何获取 WordPress 最新置顶文章列表</title>
		<link>http://eachsite.org/get-latest-sticky-posts-in-wp/</link>
		<comments>http://eachsite.org/get-latest-sticky-posts-in-wp/#comments</comments>
		<pubDate>Tue, 14 Apr 2009 06:55:54 +0000</pubDate>
		<dc:creator>辐射鱼</dc:creator>
				<category><![CDATA[WordPress 教程]]></category>
		<category><![CDATA[新手入门]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[教程]]></category>

		<guid isPermaLink="false">http://eachsite.org/?p=497</guid>
		<description><![CDATA[我们知道，WordPress2.7 新增了一个文章置顶功能（post sticky），和论坛文章置顶功能一样，当我们想让某篇文章置顶时，在“可见性”出选择“设置此文首页置顶”即可。谈到这里，可能有同学不禁要问：假如我想在侧边栏列出最新置顶文章列表该怎么办呢？
答案很简单，只需加上以下代码即可：

1
2
3
4
5
6
&#60;?php
	$sticky = get_option&#40;'sticky_posts'&#41;;
	rsort&#40; $sticky &#41;;
	$sticky = array_slice&#40; $sticky, 0, 5&#41;;
        query_posts&#40; array&#40; 'post__in' =&#62; $sticky, 'caller_get_posts' =&#62; 1 &#41; &#41;;
?&#62;

你对本篇 WordPress 教程感兴趣吗？！
通过SSH迁移WordPress博客 (13)从A到Z 26条 WordPress .htaccess 技巧 (13)如何使你的博客支持 iPhone (8)如何为 WordPress 文章创建导航目录 (14)自动为 WordPress 文章、Feed 添加版权等信息 (12)高亮 WordPress 搜索结果 JQuery 篇 (14)WordPress 不同页面、分类调用不同侧边栏详解 (9)wp_page_menu 函数使用详解 (3)使用 [...]]]></description>
			<content:encoded><![CDATA[<p>我们知道，WordPress2.7 新增了一个文章置顶功能（post sticky），和论坛文章置顶功能一样，当我们想让某篇文章置顶时，在<strong>“可见性”</strong>出选择<strong>“设置此文首页置顶”</strong>即可。谈到这里，可能有同学不禁要问：假如我想在侧边栏列出最新置顶文章列表该怎么办呢？<br />
答案很简单，只需加上以下代码即可：<span id="more-497"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
	<span style="color: #000088;">$sticky</span> <span style="color: #339933;">=</span> get_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'sticky_posts'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">rsort</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$sticky</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$sticky</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_slice</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$sticky</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        query_posts<span style="color: #009900;">&#40;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'post__in'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$sticky</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'caller_get_posts'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>你对本篇 <a href="http://eachsite.org/tag/course/">WordPress 教程</a>感兴趣吗？！</p>
<ul class="related_post"><li><a href="http://eachsite.org/transfer-wordpress-via-ssh/" title="通过SSH迁移WordPress博客">通过SSH迁移WordPress博客</a> (13)</li><li><a href="http://eachsite.org/a-to-z-of-wordpress-htaccess-hacks/" title="从A到Z 26条 WordPress .htaccess 技巧">从A到Z 26条 WordPress .htaccess 技巧</a> (13)</li><li><a href="http://eachsite.org/how-to-create-an-iphone-version-of-your-blog/" title="如何使你的博客支持 iPhone">如何使你的博客支持 iPhone</a> (8)</li><li><a href="http://eachsite.org/how-to-use-menu-in-wp-post/" title="如何为 WordPress 文章创建导航目录">如何为 WordPress 文章创建导航目录</a> (14)</li><li><a href="http://eachsite.org/auto-insert-content-after-each-post/" title="自动为 WordPress 文章、Feed 添加版权等信息">自动为 WordPress 文章、Feed 添加版权等信息</a> (12)</li><li><a href="http://eachsite.org/highlight-keywords-via-jquery/" title="高亮 WordPress 搜索结果 JQuery 篇">高亮 WordPress 搜索结果 JQuery 篇</a> (14)</li><li><a href="http://eachsite.org/how-to-get-a-particular-sidebar-in-wordpress/" title="WordPress 不同页面、分类调用不同侧边栏详解">WordPress 不同页面、分类调用不同侧边栏详解</a> (9)</li><li><a href="http://eachsite.org/wp-page-menu/" title="wp_page_menu 函数使用详解">wp_page_menu 函数使用详解</a> (3)</li><li><a href="http://eachsite.org/use-getavatar-to-add-gravatar-in-wp/" title="使用 get_avatar 为 WP 自定义 Gravatar 默认头像">使用 get_avatar 为 WP 自定义 Gravatar 默认头像</a> (22)</li><li><a href="http://eachsite.org/add-a-default-gravatar-in-wordpress/" title="如何在 WordPress 中添加 Gravatar 默认头像">如何在 WordPress 中添加 Gravatar 默认头像</a> (11)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://eachsite.org/get-latest-sticky-posts-in-wp/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>高亮 WordPress 搜索结果 JQuery 篇</title>
		<link>http://eachsite.org/highlight-keywords-via-jquery/</link>
		<comments>http://eachsite.org/highlight-keywords-via-jquery/#comments</comments>
		<pubDate>Sun, 12 Apr 2009 01:24:43 +0000</pubDate>
		<dc:creator>辐射鱼</dc:creator>
				<category><![CDATA[WordPress 教程]]></category>
		<category><![CDATA[主题开发]]></category>
		<category><![CDATA[进阶使用]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[教程]]></category>

		<guid isPermaLink="false">http://eachsite.org/?p=481</guid>
		<description><![CDATA[我曾在站趣-分享建站的乐趣提过如何高亮 WordPress 搜索关键词，可这个方法有一个缺陷，那就是只有当文章标题里有搜索关键词时才会高亮，换句话说，如果关键词出现在正文中，就并不会高亮显示。那么，有什么方法能在文章标题和正文高亮显示搜索关键词呢？当然有，那就是 JQuery。


首先，编辑主题 functions.php 文件，加入以下代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
function wps_set_query&#40;&#41; &#123;
  $query  = attribute_escape&#40;get_search_query&#40;&#41;&#41;;
&#160;
  if&#40;strlen&#40;$query&#41; &#62; 0&#41;&#123;
    echo '
      &#60;script type=&#34;text/javascript&#34;&#62;
        var wps_query  = &#34;'.$query.'&#34;;
      &#60;/script&#62;
    ';
  &#125;
&#125;
&#160;
function wps_init_jquery&#40;&#41; &#123;
 [...]]]></description>
			<content:encoded><![CDATA[<p>我曾在站趣-分享建站的乐趣提过如何<a href="http://eachsite.org/enlight-keywords-in-wp-search/">高亮 WordPress 搜索关键词</a>，可这个方法有一个缺陷，那就是只有当文章标题里有搜索关键词时才会高亮，换句话说，如果关键词出现在正文中，就并不会高亮显示。那么，有什么方法能在文章标题和正文高亮显示搜索关键词呢？当然有，那就是 JQuery。<br />
<img src="http://eachsite.org/wp-content/eachsite/2009/04/search_result-300x170.gif" alt="高亮 WordPress 搜索结果" title="高亮 WordPress 搜索结果" width="300" height="170" class="aligncenter size-medium wp-image-489" /><span id="more-481"></span></p>
<ol>
<li>首先，编辑主题 functions.php 文件，加入以下代码</li>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> wps_set_query<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$query</span>  <span style="color: #339933;">=</span> attribute_escape<span style="color: #009900;">&#40;</span>get_search_query<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'
      &lt;script type=&quot;text/javascript&quot;&gt;
        var wps_query  = &quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$query</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;;
      &lt;/script&gt;
    '</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> wps_init_jquery<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  wp_enqueue_script<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'jquery'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'init'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'wps_init_jquery'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'wp_print_scripts'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'wps_set_query'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<li>编辑主题 header.php 文件，加入以下代码：</li>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>style type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/css&quot;</span> media<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;screen&quot;</span><span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">.</span>wps <span style="color: #009900;">&#123;</span> background<span style="color: #339933;">:</span> <span style="color: #666666; font-style: italic;">#D3E18A; }
</span>  <span style="color: #339933;">&lt;/</span>style<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
  jQuery<span style="color: #339933;">.</span>fn<span style="color: #339933;">.</span>extend<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    highlight<span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>search<span style="color: #339933;">,</span> insensitive<span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">var</span> regex <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> RegExp<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;(&lt;[^&gt;]*&gt;)|(<span style="color: #000099; font-weight: bold;">\\</span>b&quot;</span><span style="color: #339933;">+</span> search<span style="color: #339933;">.</span>replace<span style="color: #009900;">&#40;</span><span style="color: #339933;">/</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span><span style="color: #339933;">-.*+</span>?^$<span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">|</span><span style="color: #009900;">&#91;</span>\<span style="color: #009900;">&#93;</span>\<span style="color: #339933;">/</span>\\<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span>g<span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\\</span><span style="color: #006699; font-weight: bold;">$1</span>&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;)&quot;</span><span style="color: #339933;">,</span> insensitive ? <span style="color: #0000ff;">&quot;ig&quot;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;g&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">return</span> this<span style="color: #339933;">.</span>html<span style="color: #009900;">&#40;</span>this<span style="color: #339933;">.</span>html<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>replace<span style="color: #009900;">&#40;</span>regex<span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>a<span style="color: #339933;">,</span> b<span style="color: #339933;">,</span> c<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span>a<span style="color: #339933;">.</span>charAt<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;&lt;&quot;</span><span style="color: #009900;">&#41;</span> ? a <span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;&lt;strong class=<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #339933;">+</span> <span style="color: #000000; font-weight: bold;">class</span> <span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&quot;</span> <span style="color: #339933;">+</span> c <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;&lt;/strong&gt;&quot;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  jQuery<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>ready<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;#post-area&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>highlight<span style="color: #009900;">&#40;</span>wps_query<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;wps&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000000; font-weight: bold;">&lt;/script&gt;</span></pre></td></tr></table></div>

<p>代码注释：<br />
①  你可将 css 写入 style.css 中；<br />
②  需将 <strong>post-area</strong> 修改为你所用主题的搜索结果所在 div；<br />
③  该段代码应放在 <strong></head></strong> 标签之前。
</ol>
<p>如何，本篇 <a href="http://eachsite.org/tag/course/">WordPress 教程</a>不复杂吧？！</p>
<ul class="related_post"><li><a href="http://eachsite.org/transfer-wordpress-via-ssh/" title="通过SSH迁移WordPress博客">通过SSH迁移WordPress博客</a> (13)</li><li><a href="http://eachsite.org/a-to-z-of-wordpress-htaccess-hacks/" title="从A到Z 26条 WordPress .htaccess 技巧">从A到Z 26条 WordPress .htaccess 技巧</a> (13)</li><li><a href="http://eachsite.org/how-to-create-an-iphone-version-of-your-blog/" title="如何使你的博客支持 iPhone">如何使你的博客支持 iPhone</a> (8)</li><li><a href="http://eachsite.org/how-to-use-menu-in-wp-post/" title="如何为 WordPress 文章创建导航目录">如何为 WordPress 文章创建导航目录</a> (14)</li><li><a href="http://eachsite.org/auto-insert-content-after-each-post/" title="自动为 WordPress 文章、Feed 添加版权等信息">自动为 WordPress 文章、Feed 添加版权等信息</a> (12)</li><li><a href="http://eachsite.org/get-latest-sticky-posts-in-wp/" title="如何获取 WordPress 最新置顶文章列表">如何获取 WordPress 最新置顶文章列表</a> (12)</li><li><a href="http://eachsite.org/how-to-get-a-particular-sidebar-in-wordpress/" title="WordPress 不同页面、分类调用不同侧边栏详解">WordPress 不同页面、分类调用不同侧边栏详解</a> (9)</li><li><a href="http://eachsite.org/wp-page-menu/" title="wp_page_menu 函数使用详解">wp_page_menu 函数使用详解</a> (3)</li><li><a href="http://eachsite.org/use-getavatar-to-add-gravatar-in-wp/" title="使用 get_avatar 为 WP 自定义 Gravatar 默认头像">使用 get_avatar 为 WP 自定义 Gravatar 默认头像</a> (22)</li><li><a href="http://eachsite.org/add-a-default-gravatar-in-wordpress/" title="如何在 WordPress 中添加 Gravatar 默认头像">如何在 WordPress 中添加 Gravatar 默认头像</a> (11)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://eachsite.org/highlight-keywords-via-jquery/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>WordPress 不同页面、分类调用不同侧边栏详解</title>
		<link>http://eachsite.org/how-to-get-a-particular-sidebar-in-wordpress/</link>
		<comments>http://eachsite.org/how-to-get-a-particular-sidebar-in-wordpress/#comments</comments>
		<pubDate>Thu, 09 Apr 2009 04:31:44 +0000</pubDate>
		<dc:creator>辐射鱼</dc:creator>
				<category><![CDATA[WordPress 教程]]></category>
		<category><![CDATA[新手入门]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[教程]]></category>

		<guid isPermaLink="false">http://eachsite.org/?p=479</guid>
		<description><![CDATA[前面，我们在如何在 WordPress2.7 调用不同的页眉、页脚、侧边栏对 WordPress 如何调用不同的侧边栏的方法进行了简单的介绍。今天，辐射鱼就和大家一起来探讨 WordPress 不同页面、分类调用不同侧边栏的具体实施方法。

不同页面调用不同侧边栏


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
&#60;?php
if&#40;is_page&#40;&#41;&#41; &#123;
    // We're on a &#34;page&#34;, which?
     if &#40;is_page&#40;'About'&#41;&#41; &#123;
        // Ah, the about page!
          get_sidebar&#40;'about'&#41;; // 调用 sidebar-about.php
    &#125; elseif &#40;is_page&#40;'archives'&#41;&#41; [...]]]></description>
			<content:encoded><![CDATA[<p>前面，我们在<a href="http://eachsite.org/how-to-get-a-particular-header-footer-or-sidebar-in-wordpress27/">如何在 WordPress2.7 调用不同的页眉、页脚、侧边栏</a>对 WordPress 如何调用不同的侧边栏的方法进行了简单的介绍。今天，辐射鱼就和大家一起来探讨 WordPress 不同页面、分类调用不同侧边栏的具体实施方法。</p>
<ol>
<li><strong>不同页面调用不同侧边栏</strong></li>
<p><span id="more-479"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>is_page<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// We're on a &quot;page&quot;, which?</span>
     <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>is_page<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'About'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// Ah, the about page!</span>
          get_sidebar<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'about'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// 调用 sidebar-about.php</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span>is_page<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'archives'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
          get_sidebar<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'archives'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// 调用 sidebar-archives.php</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span>is_page<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'contact'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
          get_sidebar<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'contact'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// 调用 sidebar-contact.php</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// if we're not any of the above pages</span>
          get_sidebar<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// 调用 sidebar.php</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    get_sidebar<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// 调用 sidebar.php</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>或者</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> 
    <span style="color: #666666; font-style: italic;">//to be able to use this outside the_Loop </span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> have_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> the_post<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> rewind_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> 
&nbsp;
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> is_home<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> is_front_page<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
        get_sidebar<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'home'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
        <span style="color: #666666; font-style: italic;">//gets sidebar-home.php </span>
    <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span> is_archive<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
        get_sidebar<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'archive'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
        <span style="color: #666666; font-style: italic;">//gets sidebar-archive.php </span>
    <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span> is_page<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
        get_sidebar<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'page'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
        <span style="color: #666666; font-style: italic;">//gets sidebar-page.php </span>
    <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span> is_single<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
        get_sidebar<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'single'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
        <span style="color: #666666; font-style: italic;">//gets sidebar-single.php </span>
    <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span> 
        get_sidebar<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> 
        <span style="color: #666666; font-style: italic;">//gets sidebar.php </span>
    <span style="color: #009900;">&#125;</span> 
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<li><strong>不同分类调用不同侧边栏</strong></li>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">//to be able to use this outside the loop</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> have_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> the_post<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> rewind_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> 
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> in_category<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'1'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
     get_sidebar<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'themes'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">//调用 sidebar-themes.php</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span> in_category<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'2'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
     get_sidebar<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'plugins'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">//调用 sidebar-plugins.php</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span> in_category<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'3'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
     get_sidebar<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'course'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">//调用 sidebar-course.php</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span> in_category<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'4'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> in_category<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'5'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> in_category<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'6'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
     get_sidebar<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'catRest'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">//调用 sidebar-catRest.php</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
     get_sidebar<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #666666; font-style: italic;">//调用 sidebar.php</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

</ol>
<p>怎么样，非常简单吧？！如果你有什么 <a href="http://eachsite.org/tag/course/">WordPress 小技巧</a>，欢迎和大家一起分享。</p>
<ul class="related_post"><li><a href="http://eachsite.org/transfer-wordpress-via-ssh/" title="通过SSH迁移WordPress博客">通过SSH迁移WordPress博客</a> (13)</li><li><a href="http://eachsite.org/a-to-z-of-wordpress-htaccess-hacks/" title="从A到Z 26条 WordPress .htaccess 技巧">从A到Z 26条 WordPress .htaccess 技巧</a> (13)</li><li><a href="http://eachsite.org/how-to-create-an-iphone-version-of-your-blog/" title="如何使你的博客支持 iPhone">如何使你的博客支持 iPhone</a> (8)</li><li><a href="http://eachsite.org/how-to-use-menu-in-wp-post/" title="如何为 WordPress 文章创建导航目录">如何为 WordPress 文章创建导航目录</a> (14)</li><li><a href="http://eachsite.org/auto-insert-content-after-each-post/" title="自动为 WordPress 文章、Feed 添加版权等信息">自动为 WordPress 文章、Feed 添加版权等信息</a> (12)</li><li><a href="http://eachsite.org/get-latest-sticky-posts-in-wp/" title="如何获取 WordPress 最新置顶文章列表">如何获取 WordPress 最新置顶文章列表</a> (12)</li><li><a href="http://eachsite.org/highlight-keywords-via-jquery/" title="高亮 WordPress 搜索结果 JQuery 篇">高亮 WordPress 搜索结果 JQuery 篇</a> (14)</li><li><a href="http://eachsite.org/wp-page-menu/" title="wp_page_menu 函数使用详解">wp_page_menu 函数使用详解</a> (3)</li><li><a href="http://eachsite.org/use-getavatar-to-add-gravatar-in-wp/" title="使用 get_avatar 为 WP 自定义 Gravatar 默认头像">使用 get_avatar 为 WP 自定义 Gravatar 默认头像</a> (22)</li><li><a href="http://eachsite.org/add-a-default-gravatar-in-wordpress/" title="如何在 WordPress 中添加 Gravatar 默认头像">如何在 WordPress 中添加 Gravatar 默认头像</a> (11)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://eachsite.org/how-to-get-a-particular-sidebar-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>wp_page_menu 函数使用详解</title>
		<link>http://eachsite.org/wp-page-menu/</link>
		<comments>http://eachsite.org/wp-page-menu/#comments</comments>
		<pubDate>Tue, 07 Apr 2009 16:30:07 +0000</pubDate>
		<dc:creator>辐射鱼</dc:creator>
				<category><![CDATA[WordPress 教程]]></category>
		<category><![CDATA[进阶使用]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[教程]]></category>

		<guid isPermaLink="false">http://eachsite.org/?p=455</guid>
		<description><![CDATA[在这篇文章中，我们将一起探讨 wp_page_menu 函数高级用法，如：

WordPress 页面多级菜单
WordPress 页面副标题
WordPress 页面链接分类
WordPress 动态菜单

WordPress 页面多级菜单
使用 wp_page_menu 函数实现 WordPress 多级页面菜单非常容易，只需添加以下代码即可：

1
2
&#60;?php wp_page_menu&#40;'exclude=1,2,3&#38;menu_class=menu menu-primary'&#41;; ?&#62;
&#60;?php wp_page_menu&#40;'include=1,2,3&#38;menu_class=menu menu-secondary'&#41;; ?&#62;

虽然，我也可以使用 wp_list_pages 函数实现多级下拉菜单，但那样的话，CSS 样式会相当复杂，不如 wp_page_menu 函数来得简洁明了。
WordPress 页面副标题

正如上图所示，有时我们需要为 WordPress 页面链接增加一些文字说明。以往，我们通常得手动修改，现在，我们可以使用 WordPress 自定义字段（custom field）来完成它了。
①	添加自定义字段

如图所示，我们只需为 WordPress 页面添加一个值为 subtitle 的自定义字段即可。
②	php 代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Adds descriptive text to link titles
// With help from http://blog.clearskys.net/2008/12/17/how-to-adding-menu-sub-titles-to-a-theme/
function sub_page_list() {
	global $wpdb;
	$sql = &#34;SELECT p.ID, p.post_title, p.guid, pm.meta_value FROM &#34; [...]]]></description>
			<content:encoded><![CDATA[<p>在这篇文章中，我们将一起探讨 <strong>wp_page_menu</strong> 函数高级用法，如：</p>
<ol>
<li><a href="#primary"><strong>WordPress 页面多级菜单</strong></a></li>
<li><a href="#subtitle"><strong>WordPress 页面副标题</strong></a></li>
<li><a href="#class"><strong>WordPress 页面链接分类</strong></a></li>
<li><a href="#dynamic"><strong>WordPress 动态菜单</strong></a></li>
</ol>
<p><a id="primary"><strong>WordPress 页面多级菜单</strong></a><br />
使用 wp_page_menu 函数实现 <a href="http://eachsite.org/tag/wordpress/">WordPress</a> 多级页面菜单非常容易，只需添加以下代码即可：<span id="more-455"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> wp_page_menu<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'exclude=1,2,3&amp;menu_class=menu menu-primary'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> wp_page_menu<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'include=1,2,3&amp;menu_class=menu menu-secondary'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>虽然，我也可以使用 wp_list_pages 函数实现多级下拉菜单，但那样的话，CSS 样式会相当复杂，不如 wp_page_menu 函数来得简洁明了。<br />
<a name="subtitle"><strong>WordPress 页面副标题</strong></a><br />
<img src="http://eachsite.org/wp-content/eachsite/2009/04/creative-display-300x50.jpg" alt="WordPress 多级页面菜单" title="WordPress 多级页面菜单" width="300" height="50" class="aligncenter size-medium wp-image-473" /><br />
正如上图所示，有时我们需要为 WordPress 页面链接增加一些文字说明。以往，我们通常得手动修改，现在，我们可以使用 WordPress 自定义字段（custom field）来完成它了。<br />
①	添加自定义字段<br />
<img src="http://eachsite.org/wp-content/eachsite/2009/04/subtitlefield-300x105.jpg" alt="subtitlefield" title="subtitlefield" width="300" height="105" class="aligncenter size-medium wp-image-474" /><br />
如图所示，我们只需为 WordPress 页面添加一个值为 subtitle 的自定义字段即可。<br />
②	php 代码</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">// Adds descriptive text to link titles
// With help from http://blog.clearskys.net/2008/12/17/how-to-adding-menu-sub-titles-to-a-theme/
function sub_page_list() {
	global $wpdb;
	$sql = &quot;SELECT p.ID, p.post_title, p.guid, pm.meta_value FROM &quot; . $wpdb-&gt;posts . &quot; AS p LEFT JOIN &quot;;
	$sql .= &quot;(SELECT post_id, meta_value FROM &quot; . $wpdb-&gt;postmeta . &quot; AS ipm WHERE meta_key = 'subtitle') &quot;;
	$sql .= &quot;AS pm ON p.ID = pm.post_id &quot;;
	$sql .= &quot;WHERE p.post_type = 'page' AND p.post_parent = 0 AND p.post_status = 'publish' &quot;;
	$sql .= &quot;ORDER BY p.menu_order ASC &quot;;
	$sql .= &quot;LIMIT 0, 10&quot;;
	$rows = $wpdb-&gt;get_results($sql,OBJECT);
	if($rows) {
		foreach($rows as $row) {
			echo &quot;&lt;li&gt;&quot;;
			$link_url = get_permalink($row-&gt;ID);
			echo &quot;&lt;a href=\&quot;$link_url\&quot;&quot; . &quot;\&quot;&gt;$row-&gt;post_title&lt;/a&gt;&quot;;
			echo &quot;&lt;span style=\&quot;display:block;\&quot;&gt;$row-&gt;meta_value&lt;/span&gt;&quot;;
			echo &quot;&lt;/li&gt;&quot;;
		}
	}
}
&nbsp;
// Filter the menu to add the list
function childtheme_page_menu() { ?&gt;
    &lt;div class=&quot;menu&quot;&gt;
        &lt;ul&gt;
            <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>is_front_page<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
            &lt;li&gt;&lt;a href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'home'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>/&quot; title=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> wp_specialchars<span style="color: #009900;">&#40;</span> get_bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; rel=&quot;home&quot;&gt;
                Home &lt;span style=&quot;display:block;&quot;&gt;This is the home page&lt;/span&gt;
            &lt;/a&gt;&lt;/li&gt;                      
            <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
            &lt;li&gt;&lt;a href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'home'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>/&quot; title=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> wp_specialchars<span style="color: #009900;">&#40;</span> get_bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; rel=&quot;home&quot;&gt;
                Home &lt;span style=&quot;display:block;&quot;&gt;Return to the home page&lt;/span&gt;
            &lt;/a&gt;&lt;/li&gt;                                 
            <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
            <span style="color: #000000; font-weight: bold;">&lt;?php</span> sub_page_list<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
        &lt;/ul&gt;
    &lt;/div&gt;    
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span>
add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'wp_page_menu'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'childtheme_page_menu'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><a id="class"><strong>WordPress 页面链接分类</strong></a><br />
我们使用 wp_page_menu 函数时遇到的一个限制是 WordPress 已经限定了其 HTML 代码，换句话说，我们只允许使用 menu-primary 和 menu-secondary 两个 class，也就是说，我们无法新增一个特殊的 class。幸运的是，我们可以使用 <strong>preg_replace</strong> 替换第一个 ul 标签，曲线解决这个问题，以下是 PHP 代码：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Add ID and CLASS attributes to the first &lt;ul&gt; occurence in wp_page_menu</span>
<span style="color: #000000; font-weight: bold;">function</span> add_menuclass<span style="color: #009900;">&#40;</span><span style="color: #000088;">$ulclass</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">return</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/&lt;ul&gt;/'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;ul id=&quot;nav&quot; class=&quot;something-classy&quot;&gt;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$ulclass</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'wp_page_menu'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'add_menuclass'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><a name="dynamic" id="dynamic"><strong>WordPress 动态菜单</strong></a></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">function my_wp_menu() { ?&gt;
&lt;div id=&quot;menu&quot;&gt;
&lt;ul&gt;
	&lt;li class=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> is_page<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'about'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>current_page_item<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>page_item<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;&lt;a href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> get_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'home'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>/about/&quot; title=&quot;About This Blog&quot;&gt;About&lt;/a&gt;&lt;/li&gt;
	&lt;li class=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> is_page<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'advertising'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>current_page_item<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>page_item<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;&lt;a href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> get_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'home'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>/advertising/&quot; title=&quot;Advertise on My Blog&quot;&gt;Advertise&lt;/a&gt;&lt;/li&gt;
	&lt;li class=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> is_page<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'contact'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>current_page_item<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>page_item<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;&lt;a href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> get_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'home'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>/contact/&quot; title=&quot;Contact Me&quot;&gt;Contact&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span>
&nbsp;
add_filter<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'wp_page_menu'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'my_wp_menu'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>代码解析：我们使用了 current_page_item 和 page_item 两个类区分当前页面和其他页面。如有其它页面，以此类推。<br />
使用方法：</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> my_wp_menu<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>怎么样，简单吧？！如果你有其他 idea，欢迎和大家一起分享！！！<br />
本文由辐射鱼翻译自：<a href="http://themeshaper.com/wordpress-menu-tricks/">WordPress Menu Tricks</a>（有删节）<br />
站趣译文：<a href="http://eachsite.org/wp-page-menu/">wp_page_menu 函数使用详解</a></p>
<ul class="related_post"><li><a href="http://eachsite.org/transfer-wordpress-via-ssh/" title="通过SSH迁移WordPress博客">通过SSH迁移WordPress博客</a> (13)</li><li><a href="http://eachsite.org/a-to-z-of-wordpress-htaccess-hacks/" title="从A到Z 26条 WordPress .htaccess 技巧">从A到Z 26条 WordPress .htaccess 技巧</a> (13)</li><li><a href="http://eachsite.org/how-to-create-an-iphone-version-of-your-blog/" title="如何使你的博客支持 iPhone">如何使你的博客支持 iPhone</a> (8)</li><li><a href="http://eachsite.org/how-to-use-menu-in-wp-post/" title="如何为 WordPress 文章创建导航目录">如何为 WordPress 文章创建导航目录</a> (14)</li><li><a href="http://eachsite.org/auto-insert-content-after-each-post/" title="自动为 WordPress 文章、Feed 添加版权等信息">自动为 WordPress 文章、Feed 添加版权等信息</a> (12)</li><li><a href="http://eachsite.org/get-latest-sticky-posts-in-wp/" title="如何获取 WordPress 最新置顶文章列表">如何获取 WordPress 最新置顶文章列表</a> (12)</li><li><a href="http://eachsite.org/highlight-keywords-via-jquery/" title="高亮 WordPress 搜索结果 JQuery 篇">高亮 WordPress 搜索结果 JQuery 篇</a> (14)</li><li><a href="http://eachsite.org/how-to-get-a-particular-sidebar-in-wordpress/" title="WordPress 不同页面、分类调用不同侧边栏详解">WordPress 不同页面、分类调用不同侧边栏详解</a> (9)</li><li><a href="http://eachsite.org/use-getavatar-to-add-gravatar-in-wp/" title="使用 get_avatar 为 WP 自定义 Gravatar 默认头像">使用 get_avatar 为 WP 自定义 Gravatar 默认头像</a> (22)</li><li><a href="http://eachsite.org/add-a-default-gravatar-in-wordpress/" title="如何在 WordPress 中添加 Gravatar 默认头像">如何在 WordPress 中添加 Gravatar 默认头像</a> (11)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://eachsite.org/wp-page-menu/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>使用 get_avatar 为 WP 自定义 Gravatar 默认头像</title>
		<link>http://eachsite.org/use-getavatar-to-add-gravatar-in-wp/</link>
		<comments>http://eachsite.org/use-getavatar-to-add-gravatar-in-wp/#comments</comments>
		<pubDate>Thu, 12 Mar 2009 15:09:45 +0000</pubDate>
		<dc:creator>辐射鱼</dc:creator>
				<category><![CDATA[WordPress 教程]]></category>
		<category><![CDATA[主题开发]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[主题]]></category>
		<category><![CDATA[教程]]></category>

		<guid isPermaLink="false">http://eachsite.org/?p=421</guid>
		<description><![CDATA[
