<?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/category/wordpress-course/advanced-using/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>Wordpress404页面在IE浏览器中不能显示的解决方案</title>
		<link>http://eachsite.org/solution-for-404-page-of-wordpress-in-ie-explorer/</link>
		<comments>http://eachsite.org/solution-for-404-page-of-wordpress-in-ie-explorer/#comments</comments>
		<pubDate>Mon, 03 Aug 2009 11:51:47 +0000</pubDate>
		<dc:creator>十二月</dc:creator>
				<category><![CDATA[WordPress 教程]]></category>
		<category><![CDATA[新手入门]]></category>
		<category><![CDATA[进阶使用]]></category>
		<category><![CDATA[404]]></category>
		<category><![CDATA[IE]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://eachsite.org/?p=852</guid>
		<description><![CDATA[Wordpress在IE浏览器中，其404页面被IE自带的页面取代，这对站点很不利，其实只需要做一小修改就可以解决问题。
在404页面的上方，get_header之上添加
&#60;?php ob_start(); ?&#62;
&#60;?php header(”HTTP/1.1 404 Not Found”); ?&#62;
WordPress 主题 Ari (10)WordPress 主题 High Art Blog (3)Google +1 按钮 WordPress 插件 (7)WordPress主题巴士今日上线 (5)WordPress 主题 Imbalance (5)站趣新版上线 (16)WordPress 主题 tanzaku (10)通过SSH迁移WordPress博客 (13)Wordpress 主题 WP Remix (2)Wordpress 主题 Js O4w (2)]]></description>
			<content:encoded><![CDATA[<p>Wordpress在IE浏览器中，其404页面被IE自带的页面取代，这对站点很不利，其实只需要做一小修改就可以解决问题。<br />
在404页面的上方，get_header之上添加<br />
&lt;?php ob_start(); ?&gt;</p>
<p>&lt;?php header(”HTTP/1.1 404 Not Found”); ?&gt;</p>
<ul class="related_post"><li><a href="http://eachsite.org/wordpress-theme-ari/" title="WordPress 主题 Ari">WordPress 主题 Ari</a> (10)</li><li><a href="http://eachsite.org/wordpress-theme-high-art/" title="WordPress 主题 High Art Blog">WordPress 主题 High Art Blog</a> (3)</li><li><a href="http://eachsite.org/google-1-button-for-wordpress-plugin/" title="Google +1 按钮 WordPress 插件">Google +1 按钮 WordPress 插件</a> (7)</li><li><a href="http://eachsite.org/wpus-online-today/" title="WordPress主题巴士今日上线">WordPress主题巴士今日上线</a> (5)</li><li><a href="http://eachsite.org/wordpress-theme-imbalance/" title="WordPress 主题 Imbalance">WordPress 主题 Imbalance</a> (5)</li><li><a href="http://eachsite.org/eachsite-new-wp-cms-theme-online/" title="站趣新版上线">站趣新版上线</a> (16)</li><li><a href="http://eachsite.org/wordpress-them-tanzaku/" title="WordPress 主题 tanzaku">WordPress 主题 tanzaku</a> (10)</li><li><a href="http://eachsite.org/transfer-wordpress-via-ssh/" title="通过SSH迁移WordPress博客">通过SSH迁移WordPress博客</a> (13)</li><li><a href="http://eachsite.org/wordpress-theme-wp-remix/" title="Wordpress 主题 WP Remix">Wordpress 主题 WP Remix</a> (2)</li><li><a href="http://eachsite.org/wordpress-theme-js-o4w/" title="Wordpress 主题 Js O4w">Wordpress 主题 Js O4w</a> (2)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://eachsite.org/solution-for-404-page-of-wordpress-in-ie-explorer/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>四种去除 WordPress 永久链接中讨厌的 category 方法</title>
		<link>http://eachsite.org/4-ways-to-remove-category-from-your-wordpress-url/</link>
		<comments>http://eachsite.org/4-ways-to-remove-category-from-your-wordpress-url/#comments</comments>
		<pubDate>Wed, 13 May 2009 13:10:21 +0000</pubDate>
		<dc:creator>Showfom</dc:creator>
				<category><![CDATA[WordPress 教程]]></category>
		<category><![CDATA[进阶使用]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[永久链接]]></category>

		<guid isPermaLink="false">http://eachsite.org/?p=660</guid>
		<description><![CDATA[默认的 WordPress 地址中，分类地址总有一个 category ，看着就比较讨厌，比如 站趣 的 WordPress 教程 分类地址就是 http://eachsite.org/category/wordpress-course/
由于我对永久链接（Permalink）比较过敏，别笑，在座的各位肯定有比我更加过敏的，所以我单篇日志的永久链接设置成/%postname%/，然后分类，总是有一个讨厌的category，在网上找了N多个方法，总结一下。
首先看了任平生的方法，详见这里，说的是把category的永久链接设置成一个点号“.”，就这么一点就是了，结果，404错误。
然后看到了网上比较流行的通过 .htaccess 修改的方法，但是，全部是301，而且网页上显示的链接还是带有 category 的，只有点击以后才能访问，详细方法见这里。
下定决心一定要找一个好的方法，看到老外的留言，试了几个插件，首先用了Top Level Categories，不行，还是404错误，接着，看到了一丝曙光，一个老外说只要用Decategorizer和Redirection搭配使用就没问题，嗯，你们现在看到的我的博客的分类永久链接使用的方法就是这种。
方法总结：

把分类的永久链接形式设置成一个点号“.”（WordPress 2.5以上才能用），但是能不能出现404错误就是你的人品问题了。
使用,htaccess的方法，具体代码：

RewriteRule ^category/&#40;.+&#41;$ http://www.yourblog.com/$1 [R=301,L]

把www.yourblog.com改成你的博客地址，这种方法的缺点是显示的还是原来的，只有点击了才会301转向，造成博客上301转向地址过多
使用Top Level Categories，只要后台激活就行，但是分类的page代码，比如http://xxx/news/page/2会变成http://xxx/news/pageid?=2这样的形式，很难看
使用Decategorizer和Redirection的组合，方法：下载上传激活Decategorizer，启用，然后下载上传激活Redirection，启用，OK，一切完毕，世界清净了。

看一下我的演示吧：http://showfom.com/wordpress/ 觉得特别有成就感，哈哈。不过有一点小BUG，生成的SiteMap里的分类的链接最后没有一个斜杠“/”，嗯，别生成分类的SiteMap吧。
文章来源：http://showfom.com/4-ways-to-remove-category-from-your-wordpress-url/
WordPress 主题 Ari (10)WordPress 主题 High Art Blog (3)Google +1 按钮 WordPress 插件 (7)WordPress主题巴士今日上线 (5)WordPress 主题 Imbalance (5)站趣新版上线 (16)WordPress 主题 tanzaku (10)通过SSH迁移WordPress博客 (13)Wordpress 主题 WP Remix (2)Wordpress 主题 Js O4w (2)]]></description>
			<content:encoded><![CDATA[<p>默认的 WordPress 地址中，分类地址总有一个 category ，看着就比较讨厌，比如 <a href="http://eachsite.org/">站趣</a> 的 <a href="http://eachsite.org/category/wordpress-course/">WordPress 教程</a> 分类地址就是 http://eachsite.org/category/wordpress-course/</p>
<p>由于我对永久链接（Permalink）比较过敏，别笑，在座的各位肯定有比我更加过敏的，所以我单篇日志的永久链接设置成/%postname%/，然后分类，总是有一个讨厌的category，在网上找了N多个方法，总结一下。<span id="more-660"></span></p>
<p>首先看了任平生的方法，详见<a href="http://rpsh.net/archives/remove-the-category-prefix-from-permalinks-on-wordpress/">这里</a>，说的是把category的永久链接设置成一个点号“.”，就这么一点就是了，结果，404错误。</p>
<p>然后看到了网上比较流行的通过 .htaccess 修改的方法，但是，全部是301，而且网页上显示的链接还是带有 category 的，只有点击以后才能访问，详细方法见<a href="http://www.wprecipes.com/how-to-remove-category-from-your-wordpress-url">这里</a>。<br />
下定决心一定要找一个好的方法，看到老外的留言，试了几个插件，首先用了<a href="http://wordpress.org/extend/plugins/top-level-cats/">Top Level Categories</a>，不行，还是404错误，接着，看到了一丝曙光，一个老外说只要用<a href="http://wordpress.org/extend/plugins/decategorizer/">Decategorizer</a>和<a href="http://wordpress.org/extend/plugins/redirection/">Redirection</a>搭配使用就没问题，嗯，你们现在看到的我的博客的分类永久链接使用的方法就是这种。</p>
<p><strong>方法总结：</strong></p>
<ol>
<li>把分类的永久链接形式设置成一个点号“.”（WordPress 2.5以上才能用），但是能不能出现404错误就是你的人品问题了。</li>
<li>使用,htaccess的方法，具体代码：

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">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;">//www.yourblog.com/$1 [R=301,L]</span></pre></div></div>

<p>把<a href="http://www.yourblog.com/">www.yourblog.com</a>改成你的博客地址，这种方法的缺点是显示的还是原来的，只有点击了才会301转向，造成博客上301转向地址过多</li>
<li>使用<a href="http://wordpress.org/extend/plugins/top-level-cats/">Top Level Categories</a>，只要后台激活就行，但是分类的page代码，比如http://xxx/news/page/2会变成http://xxx/news/pageid?=2这样的形式，很难看</li>
<li>使用<a href="http://wordpress.org/extend/plugins/decategorizer/">Decategorizer</a>和<a href="http://wordpress.org/extend/plugins/redirection/">Redirection</a>的组合，方法：下载上传激活<a href="http://wordpress.org/extend/plugins/decategorizer/">Decategorizer</a>，启用，然后下载上传激活<a href="http://wordpress.org/extend/plugins/redirection/">Redirection</a>，启用，OK，一切完毕，世界清净了。</li>
</ol>
<p>看一下我的演示吧：<a href="http://showfom.com/wordpress/">http://showfom.com/wordpress/</a> 觉得特别有成就感，哈哈。不过有一点小BUG，生成的<a href="http://showfom.com/sitemap.xml">SiteMap</a>里的分类的链接最后没有一个斜杠“/”，嗯，别生成分类的SiteMap吧。<br />
文章来源：<a href="http://showfom.com/4-ways-to-remove-category-from-your-wordpress-url/">http://showfom.com/4-ways-to-remove-category-from-your-wordpress-url/</a></p>
<ul class="related_post"><li><a href="http://eachsite.org/wordpress-theme-ari/" title="WordPress 主题 Ari">WordPress 主题 Ari</a> (10)</li><li><a href="http://eachsite.org/wordpress-theme-high-art/" title="WordPress 主题 High Art Blog">WordPress 主题 High Art Blog</a> (3)</li><li><a href="http://eachsite.org/google-1-button-for-wordpress-plugin/" title="Google +1 按钮 WordPress 插件">Google +1 按钮 WordPress 插件</a> (7)</li><li><a href="http://eachsite.org/wpus-online-today/" title="WordPress主题巴士今日上线">WordPress主题巴士今日上线</a> (5)</li><li><a href="http://eachsite.org/wordpress-theme-imbalance/" title="WordPress 主题 Imbalance">WordPress 主题 Imbalance</a> (5)</li><li><a href="http://eachsite.org/eachsite-new-wp-cms-theme-online/" title="站趣新版上线">站趣新版上线</a> (16)</li><li><a href="http://eachsite.org/wordpress-them-tanzaku/" title="WordPress 主题 tanzaku">WordPress 主题 tanzaku</a> (10)</li><li><a href="http://eachsite.org/transfer-wordpress-via-ssh/" title="通过SSH迁移WordPress博客">通过SSH迁移WordPress博客</a> (13)</li><li><a href="http://eachsite.org/wordpress-theme-wp-remix/" title="Wordpress 主题 WP Remix">Wordpress 主题 WP Remix</a> (2)</li><li><a href="http://eachsite.org/wordpress-theme-js-o4w/" title="Wordpress 主题 Js O4w">Wordpress 主题 Js O4w</a> (2)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://eachsite.org/4-ways-to-remove-category-from-your-wordpress-url/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>高亮 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>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>如何在 WordPress 中添加 Gravatar 默认头像</title>
		<link>http://eachsite.org/add-a-default-gravatar-in-wordpress/</link>
		<comments>http://eachsite.org/add-a-default-gravatar-in-wordpress/#comments</comments>
		<pubDate>Wed, 11 Mar 2009 16:10:21 +0000</pubDate>
		<dc:creator>辐射鱼</dc:creator>
				<category><![CDATA[WordPress 教程]]></category>
		<category><![CDATA[主题开发]]></category>
		<category><![CDATA[进阶使用]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[主题]]></category>
		<category><![CDATA[教程]]></category>

		<guid isPermaLink="false">http://eachsite.org/?p=417</guid>
		<description><![CDATA[我们知道 WordPress 会自动匹配评论者/留言者的 email 并据此显示其 Gravatar 头像，但对于仍未使用 Gravatar 头像的评论者/留言者，便只显示丑丑的默认头像。你是不是和辐射鱼一样，早看这几个丑丑的默认头像不顺眼了呢？别担心，强大的 WordPress 已经为我们考虑到了这个问题，我们只需用 WordPress filter action 替换 avatar_defaults，即可新增一个图片作为默认头像，效果图如下：

add_filter() 过滤器函数使用释疑：
我们使用 WordPress 函数时，可以通过 add_filter() 过滤器钩子添加你的新过滤器。使用方法：

add_filter&#40;’hook_name’, ‘your_filter’, &#91;priority&#93;, &#91;accepted_args&#93;&#41;;

hook_name：WordPress 提供的过滤器钩子，即你要 hack 的函数；
your_filter：你为 hook_name 定义的新函数名，它可以是一个 php 自带函数,一个 WordPress 核心函数,或是一个你的自定义函数；
priority：这是一个整型的可选参数，它用来指定为一个过滤器钩子应用过滤器的顺序，其默认值为10，一个拥有优先级为 1 的过滤器将会比拥有优先级为 2 的先被应用，数字越小，其优先级将越高；
accepted_args：这也是一个整型的可选参数，用以定义你的函数能接收多少个参数，默认值为 1。
下面，开始我们的小手术吧！！！
在主题 functions.php 文件中自定义 Gravatar 默认头像：

1
2
3
4
5
6
7
8
// add default gravatar
add_filter&#40; 'avatar_defaults', 'newgravatar' &#41;;
&#160;
function newgravatar &#40;$avatar_defaults&#41; &#123;
    $myavatar [...]]]></description>
			<content:encoded><![CDATA[<p>我们知道 <a href="http://eachsite.org/tag/wordpress/">WordPress</a> 会自动匹配评论者/留言者的 email 并据此显示其 <a href="http://www.gravatar.com/">Gravatar</a> 头像，但对于仍未使用 Gravatar 头像的评论者/留言者，便只显示丑丑的默认头像。你是不是和辐射鱼一样，早看这几个丑丑的默认头像不顺眼了呢？别担心，强大的 WordPress 已经为我们考虑到了这个问题，我们只需用 WordPress filter action 替换 <strong>avatar_defaults</strong>，即可新增一个图片作为默认头像，效果图如下：<br />
<img src="http://eachsite.org/wp-content/eachsite/2009/03/add-default-gravatar-300x202.gif" alt="在 WordPress 中添加默认 Gravatar 头像" title="在 WordPress 中添加默认 Gravatar 头像" width="300" height="202" class="aligncenter size-medium wp-image-418" /><br />
<strong>add_filter() 过滤器函数使用释疑</strong>：<br />
我们使用 WordPress 函数时，可以通过 <strong>add_filter()</strong> 过滤器钩子添加你的新过滤器。使用方法：<span id="more-417"></span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">add_filter<span style="color: #009900;">&#40;</span>’hook_name’<span style="color: #339933;">,</span> ‘your_filter’<span style="color: #339933;">,</span> <span style="color: #009900;">&#91;</span>priority<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#91;</span>accepted_args<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><strong>hook_name</strong>：WordPress 提供的过滤器钩子，即你要 hack 的函数；<br />
<strong>your_filter</strong>：你为 hook_name 定义的新函数名，它可以是一个 php 自带函数,一个 WordPress 核心函数,或是一个你的自定义函数；<br />
<strong>priority</strong>：这是一个整型的可选参数，它用来指定为一个过滤器钩子应用过滤器的顺序，其默认值为10，一个拥有优先级为 1 的过滤器将会比拥有优先级为 2 的先被应用，数字越小，其优先级将越高；<br />
<strong>accepted_args</strong>：这也是一个整型的可选参数，用以定义你的函数能接收多少个参数，默认值为 1。<br />
下面，开始我们的小手术吧！！！<br />
<strong>在主题 functions.php 文件中自定义 Gravatar 默认头像</strong>：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// add default gravatar</span>
add_filter<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'avatar_defaults'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'newgravatar'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> newgravatar <span style="color: #009900;">&#40;</span><span style="color: #000088;">$avatar_defaults</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$myavatar</span> <span style="color: #339933;">=</span> get_bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'template_directory'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/images/boy.jpg'</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$avatar_defaults</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$myavatar</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;eachSite&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$avatar_defaults</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><strong>使用方法</strong>：</p>
<ol>
<li>复制以上代码到主题 functions.php 文件中</li>
<li>上传 boy.jpg 文件到 wp-content/themes/yourusingtheme/images/ 目录</li>
</ol>
<p><strong>update:经雪深提醒，新增<a href="http://eachsite.org/use-getavatar-to-add-gravatar-in-wp/">使用 get_avatar 为 WP 自定义 Gravatar 默认头像</a></strong><br />
另外：使用 WordPress2.7 的同学，最好使用 add_filter() 为 WordPress 添加 Gravatar 默认头像！！！<br />
怎么样，对这篇 <a href="http://eachsite.org/tag/course/">WordPress 教程</a>感兴趣吧？</p>
<ul class="related_post"><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/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/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><li><a href="http://eachsite.org/safest-way-to-include-plugin-code-in-themes/" title="在 WordPress 主题中安全的调用插件代码">在 WordPress 主题中安全的调用插件代码</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://eachsite.org/add-a-default-gravatar-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>WordPress CMS 主题技巧：显示 WordPress 分类图片</title>
		<link>http://eachsite.org/show-wordpress-category-images/</link>
		<comments>http://eachsite.org/show-wordpress-category-images/#comments</comments>
		<pubDate>Wed, 18 Feb 2009 16:21:46 +0000</pubDate>
		<dc:creator>辐射鱼</dc:creator>
				<category><![CDATA[WordPress 教程]]></category>
		<category><![CDATA[主题开发]]></category>
		<category><![CDATA[进阶使用]]></category>
		<category><![CDATA[cms]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[主题]]></category>
		<category><![CDATA[教程]]></category>

		<guid isPermaLink="false">http://eachsite.org/?p=379</guid>
		<description><![CDATA[在看了上一篇 WordPress CMS 技巧：按照分类调用最新文章之后，你是不是觉得能为分类添加图片就更完美呢？
我们知道，WordPress 暂时还不支持为分类添加图片，但这难不倒我们众多的 WordPress 爱好者，我们稍微 DIY  一下 WordPress 主题，一个山寨 WordPress 分类图标就出来了。
思路：我们知道，get the category 可以获取 cat_ID（分类 ID）、cat_name（分类名）、category_nicename（分类缩略名）、category_description（分类描述）、category_parent（分类层级） 以及 category_count 等信息，那么，我们就可以用 category_nicename 命名图片，然后匹配并输出。可能有点拗口，看下代码吧，很简单：

1
2
3
4
5
6
7
8
9
10
11
12
&#60;em&#62;Posted in:&#60;/em&#62;
&#60;?php foreach&#40;&#40;get_the_category&#40;&#41;&#41; as $cat&#41;
	&#123;
	$catname =$cat-&#62;category_nicename;
	echo &#34;&#60;a href\&#34;/category/&#34;;
	echo $catname;
	echo &#34;/\&#34;&#62;&#34;;
	echo &#34;&#60;img src\&#34;/wp-content/cat-icons/&#34;;
	echo $catname;
	echo &#34;.png\&#34; alt=\&#34;$catname category image\&#34; border=\&#34;0\&#34; /&#62;&#60;/a&#62;\n&#34;;
	&#125;
?&#62;

代码很简单，就是查询日志所在分类及其缩略名，然后自动在 cat-icons 目录匹配 category_nicename.png，然后输出。当然，你可以更改.png为任何图片格式。
怎么样，很简单吧？！如果你有什么 idea，欢迎来站趣-分享建站的乐趣讨论。
WordPress CMS 技巧：按照分类调用最新文章 (26)站趣新版上线 (16)如何使你的博客支持 iPhone (8)使用 get_avatar 为 WP [...]]]></description>
			<content:encoded><![CDATA[<p>在看了上一篇 <a href="http://eachsite.org/wordpress-cms-tips-latest-posts-by-cat/">WordPress CMS 技巧：按照分类调用最新文章</a>之后，你是不是觉得能为分类添加图片就更完美呢？<br />
我们知道，<a href="http://eachsite.org/tag/wordpress/">WordPress</a> 暂时还不支持为分类添加图片，但这难不倒我们众多的 WordPress 爱好者，我们稍微 DIY  一下 <a href="http://eachsite.org/category/wordpress-themes/themes-intro/">WordPress 主题</a>，一个山寨 WordPress 分类图标就出来了。<br />
思路：我们知道，<strong>get the category</strong> 可以获取 cat_ID（分类 ID）、cat_name（分类名）、category_nicename（分类缩略名）、category_description（分类描述）、category_parent（分类层级） 以及 category_count 等信息，那么，我们就可以用<span id="more-379"></span> category_nicename 命名图片，然后匹配并输出。可能有点拗口，看下代码吧，很简单：</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;">&lt;em&gt;Posted in:&lt;/em&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>get_the_category<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$cat</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$catname</span> <span style="color: #339933;">=</span><span style="color: #000088;">$cat</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">category_nicename</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;a href<span style="color: #000099; font-weight: bold;">\&quot;</span>/category/&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$catname</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;/<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;img src<span style="color: #000099; font-weight: bold;">\&quot;</span>/wp-content/cat-icons/&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$catname</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;.png<span style="color: #000099; font-weight: bold;">\&quot;</span> alt=<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #006699; font-weight: bold;">$catname</span> category image<span style="color: #000099; font-weight: bold;">\&quot;</span> border=<span style="color: #000099; font-weight: bold;">\&quot;</span>0<span style="color: #000099; font-weight: bold;">\&quot;</span> /&gt;&lt;/a&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>代码很简单，就是查询日志所在分类及其缩略名，然后自动在 <strong>cat-icons</strong> 目录匹配 category_nicename.png，然后输出。当然，你可以更改.png为任何图片格式。<br />
怎么样，很简单吧？！如果你有什么 idea，欢迎来<a href="http://eachsite.org/">站趣-分享建站的乐趣</a>讨论。</p>
<ul class="related_post"><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/eachsite-new-wp-cms-theme-online/" title="站趣新版上线">站趣新版上线</a> (16)</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/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/wordpress-cms-theme-comfymagazine/" title="情人节礼物 WordPress CMS 主题 ComFy Magazine">情人节礼物 WordPress CMS 主题 ComFy Magazine</a> (13)</li><li><a href="http://eachsite.org/wordpress-cms-theme-hybrid-news/" title="WordPress CMS 主题 Hybrid News">WordPress CMS 主题 Hybrid News</a> (13)</li><li><a href="http://eachsite.org/wordpress-shortcodes/" title="精通 WordPress 短代码">精通 WordPress 短代码</a> (6)</li><li><a href="http://eachsite.org/free-wordpress-themes-mimbo3/" title="WordPress 免费主题 Mimbo3.0">WordPress 免费主题 Mimbo3.0</a> (7)</li><li><a href="http://eachsite.org/free-wordpress-cms-theme-thestars/" title="Free WordPress CMS 主题 the stars">Free WordPress CMS 主题 the stars</a> (4)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://eachsite.org/show-wordpress-category-images/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>WordPress CMS 技巧：按照分类调用最新文章</title>
		<link>http://eachsite.org/wordpress-cms-tips-latest-posts-by-cat/</link>
		<comments>http://eachsite.org/wordpress-cms-tips-latest-posts-by-cat/#comments</comments>
		<pubDate>Mon, 16 Feb 2009 16:30:59 +0000</pubDate>
		<dc:creator>辐射鱼</dc:creator>
				<category><![CDATA[WordPress 教程]]></category>
		<category><![CDATA[主题开发]]></category>
		<category><![CDATA[进阶使用]]></category>
		<category><![CDATA[cms]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[主题]]></category>
		<category><![CDATA[教程]]></category>

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