<?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>睡到25点 &#187; WordPress</title>
	<atom:link href="http://www.voidman.com/tag/wordpress/feed" rel="self" type="application/rss+xml" />
	<link>http://www.voidman.com</link>
	<description>个人博客，记录与分享，仅此而已。</description>
	<lastBuildDate>Fri, 30 Jul 2010 09:54:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>WordPress 的 Hook 机制在 Discuz 二次开发中的应用</title>
		<link>http://www.voidman.com/2009/05/using-wordpress-plugin-api-hack-discuz.html</link>
		<comments>http://www.voidman.com/2009/05/using-wordpress-plugin-api-hack-discuz.html#comments</comments>
		<pubDate>Fri, 01 May 2009 16:41:30 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[discuz]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[hook]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.voidman.com/?p=285</guid>
		<description><![CDATA[最近工作需要对 Discuz 做二次开发，本着最小化改动方便以后升级的原则，我引入了 WordPress 的 Hook 机制（即 Plugin API）来降低二次开发代码与 Discuz 原生代码的耦合度。 WordPress 内部提供了许多 Hook（钩子），以便插件可以将相应的 action 或 filter 挂接上去接管或改进 WordPress 的默认处理来达到自己期望的目的，在处理完毕后将控制权重新交给 WordPress。而我们所要做的就是将这种机制移植到 Discuz 中，所幸的是，WordPress 的 Hook 机制并没有过多地依赖于它的其它核心程序，所以基本不需要做多少修改就可以拿来使用。 基本步骤 在 Discuz 安装目录新建一个文件夹，命名为extra，复制 WordPress 的wp-includes/plugin.php文件到此文件夹。为了符合 Discuz 名命名规范，将文件重命名为plugin.func.php 为了避免潜在的函数命名冲突，可以将plugin.func.php文件里的函数名称都加上前缀，例如do_action()修改成dz_do_action()；另外 plugin_basename(), register_activation_hook(), register_deactivation_hook(), register_uninstall_hook() 等函数可以删除。 在extra文件夹新建一个php文件，命名为hooks.inc.php，这里放置绝大部分 filter 和 action，将它们放在该文件中的一个最大的好处是方便集中维护。 载入相关文件。打开include/common.inc.php文件，找到 require_once DISCUZ_ROOT.'./config.inc.php'; 在该行代码下面添加 require_once DISCUZ_ROOT.'./extra/plugin.func.php'; require_once DISCUZ_ROOT.'./extra/hooks.inc.php'; 至此，基本的 Hook 机制已经建立 [...]]]></description>
			<content:encoded><![CDATA[<p>最近工作需要对 Discuz 做二次开发，本着最小化改动方便以后升级的原则，我引入了 WordPress 的 Hook 机制（即 Plugin API）来降低二次开发代码与 Discuz 原生代码的耦合度。</p>
<p>WordPress 内部提供了许多 Hook（钩子），以便插件可以将相应的 action 或 filter 挂接上去接管或改进 WordPress 的默认处理来达到自己期望的目的，在处理完毕后将控制权重新交给 WordPress。而我们所要做的就是将这种机制移植到 Discuz 中，所幸的是，WordPress 的 Hook 机制并没有过多地依赖于它的其它核心程序，所以基本不需要做多少修改就可以拿来使用。<br />
<span id="more-285"></span><br />
<strong>基本步骤</strong></p>
<ol>
<li>在 Discuz 安装目录新建一个文件夹，命名为<code>extra</code>，复制 WordPress 的<code>wp-includes/plugin.php</code>文件到此文件夹。为了符合 Discuz 名命名规范，将文件重命名为<code>plugin.func.php</code></li>
<li>为了避免潜在的函数命名冲突，可以将<code>plugin.func.php</code>文件里的函数名称都加上前缀，例如<code>do_action()</code>修改成<code>dz_do_action()</code>；另外 <code>plugin_basename()</code>, <code>register_activation_hook()</code>, <code>register_deactivation_hook()</code>, <code>register_uninstall_hook()</code> 等函数可以删除。</li>
<li>在<code>extra</code>文件夹新建一个php文件，命名为<code>hooks.inc.php</code>，这里放置绝大部分 filter 和 action，将它们放在该文件中的一个最大的好处是方便集中维护。</li>
<li>载入相关文件。打开<code>include/common.inc.php</code>文件，找到

<div class="wp_syntax"><pre class="php"><span style="color: blue;">require_once</span> DISCUZ_ROOT.<span style="color: #ff00ff;">'./config.inc.php'</span>;</pre></div>

<p>在该行代码下面添加</p>

<div class="wp_syntax"><pre class="php"><span style="color: blue;">require_once</span> DISCUZ_ROOT.<span style="color: #ff00ff;">'./extra/plugin.func.php'</span>;
<span style="color: blue;">require_once</span> DISCUZ_ROOT.<span style="color: #ff00ff;">'./extra/hooks.inc.php'</span>;</pre></div>

<p>至此，基本的 Hook 机制已经建立
</li>
</ol>
<p><strong>实际应用示例</strong></p>
<p>接下来我们就可以开始添加自己的代码了。举个例子，Discuz 中<code>$discuz_auth_key</code>是这样定义的：</p>

<div class="wp_syntax"><pre class="php"><span style="color: #008080;">$discuz_auth_key</span> = <span style="color: #ff0000;">md5</span><span style="color: #800000;">&#40;</span><span style="color: #008080;">$_DCACHE</span><span style="color: #800000;">&#91;</span><span style="color: #ff00ff;">'settings'</span><span style="color: #800000;">&#93;</span><span style="color: #800000;">&#91;</span><span style="color: #ff00ff;">'authkey'</span><span style="color: #800000;">&#93;</span>.<span style="color: #008080;">$_SERVER</span><span style="color: #800000;">&#91;</span><span style="color: #ff00ff;">'HTTP_USER_AGENT'</span><span style="color: #800000;">&#93;</span><span style="color: #800000;">&#41;</span>;</pre></div>

<p>如果想将<code>$discuz_auth_key</code>的定义修改为<code>md5(authkey+user_agent+ip)</code>这样的形式，我们可以通过 filter 来实现。在<code>$discuz_auth_key</code>的定义代码下一行添加：</p>

<div class="wp_syntax"><pre class="php"><span style="color: #008000; font-style: italic;">// 生成一个名为 discuz_auth_key 的钩子</span>
<span style="color: #008080;">$discuz_auth_key</span> = dz_apply_filters<span style="color: #800000;">&#40;</span><span style="color: #ff00ff;">'discuz_auth_key'</span>, <span style="color: #008080;">$discuz_auth_key</span>, <span style="color: #008080;">$_DCACHE</span><span style="color: #800000;">&#91;</span><span style="color: #ff00ff;">'settings'</span><span style="color: #800000;">&#93;</span><span style="color: #800000;">&#91;</span><span style="color: #ff00ff;">'authkey'</span><span style="color: #800000;">&#93;</span>, <span style="color: #008080;">$_SERVER</span><span style="color: #800000;">&#91;</span><span style="color: #ff00ff;">'HTTP_USER_AGENT'</span><span style="color: #800000;">&#93;</span>, <span style="color: #008080;">$onlineip</span><span style="color: #800000;">&#41;</span>;</pre></div>

<p>然后打开<code>hooks.inc.php</code>文件，添加以下代码</p>

<div class="wp_syntax"><pre class="php"><span style="color: #008000; font-style: italic;">// 为了方便维护，所有 filter 类 hook 都以 filter_ 为前缀</span>
<span style="color: blue;">function</span> filter_discuz_auth_key<span style="color: #800000;">&#40;</span><span style="color: #008080;">$discuz_auth_key</span>, <span style="color: #008080;">$authkey</span>, <span style="color: #008080;">$ua</span>, <span style="color: #008080;">$ip</span><span style="color: #800000;">&#41;</span> <span style="color: #800000;">&#123;</span>
  <span style="color: #008000; font-style: italic;">// 符合自己设定的条件时才重新定义 authkey</span>
  <span style="color: #008000; font-style: italic;">// 否则返回 Discuz 定义的 discuz_auth_key 原值</span>
  <span style="color: blue;">if</span> <span style="color: #800000;">&#40;</span><span style="color: #008080;">$authkey</span> &amp;&amp; <span style="color: #008080;">$ua</span> &amp;&amp; <span style="color: #008080;">$ip</span><span style="color: #800000;">&#41;</span> <span style="color: #800000;">&#123;</span>
    <span style="color: #008080;">$discuz_auth_key</span> = <span style="color: #ff0000;">md5</span><span style="color: #800000;">&#40;</span><span style="color: #008080;">$authkey</span> . <span style="color: #008080;">$ua</span> . <span style="color: #008080;">$ip</span><span style="color: #800000;">&#41;</span>;
  <span style="color: #800000;">&#125;</span>
  <span style="color: blue;">return</span> <span style="color: #008080;">$discuz_auth_key</span>;
<span style="color: #800000;">&#125;</span>
&nbsp;
<span style="color: #008000; font-style: italic;">// 将 filter 函数 filter_discuz_auth_key 挂接到 discuz_auth_key 钩子上</span>
<span style="color: #008000; font-style: italic;">// 第三个参数的值 10 代表执行优先级，因为一个钩子上可以挂接多个callback函数</span>
<span style="color: #008000; font-style: italic;">// 第四个参数的值 4 代表允许 filter_discuz_auth_key 函数接收的参数个数</span>
add_filter<span style="color: #800000;">&#40;</span><span style="color: #ff00ff;">'discuz_auth_key'</span>, <span style="color: #ff00ff;">'filter_discuz_auth_key'</span>, <span style="color: #800080;">10</span>, <span style="color: #800080;">4</span><span style="color: #800000;">&#41;</span>;</pre></div>

<p>这样便达到我们所要的效果了。当然有些情况下还是无法避免了二次开发代码与原代码的夹杂在一起，不过由于有了 Hook 机制，这种情形已经可以大大减少了。</p>
<p><strong>相关阅读</strong><br />
<a href="http://codex.wordpress.org/Plugin_API">WordPress Plugin API</a></p>
<h4>Related Posts</h4><ul class="related_post"><li><a href="http://www.voidman.com/2009/11/media-temple-hacked.html" title="Media Temple Hacked">Media Temple Hacked</a></li><li><a href="http://www.voidman.com/2009/05/mogilefs-for-discuz.html" title="在 Discuz 中应用 MogileFS 分布式文件存储系统">在 Discuz 中应用 MogileFS 分布式文件存储系统</a></li><li><a href="http://www.voidman.com/2009/04/at-reply-mail-notification-1-release.html" title="At Reply Mail Notification 1.0 Release">At Reply Mail Notification 1.0 Release</a></li><li><a href="http://www.voidman.com/2009/03/lbs-to-wordpress.html" title="LBS 转 WordPress 不完全记录">LBS 转 WordPress 不完全记录</a></li><li><a href="http://www.voidman.com/2009/01/wordpress-is-using-a-bad-way-to-detect-duplicate-comment.html" title="Wordpress 糟糕的重复评论检测方式">Wordpress 糟糕的重复评论检测方式</a></li><li><a href="http://www.voidman.com/2009/01/at-reply-mail-notification-test.html" title="At Reply Mail Notification 测试贴">At Reply Mail Notification 测试贴</a></li><li><a href="http://www.voidman.com/2008/11/automatically-delete-post-revisions.html" title="让 Wordpress 自动删除 Post Revisions">让 Wordpress 自动删除 Post Revisions</a></li><li><a href="http://www.voidman.com/2008/11/google-xml-sitemaps-ignore-the-specified-categories.html" title="让 Google Sitemaps Generator 可以忽略指定的日志分类">让 Google Sitemaps Generator 可以忽略指定的日志分类</a></li><li><a href="http://www.voidman.com/2008/11/the-better-solution-for-static-paged-post.html" title="Wordpress 分页文章静态化的更优解决方案">Wordpress 分页文章静态化的更优解决方案</a></li><li><a href="http://www.voidman.com/2008/07/upgraded-to-wordpress-v26.html" title="升级到 WordPress 2.6">升级到 WordPress 2.6</a></li></ul><hr /><a href="http://www.voidman.com">Voidman.com</a> | Link: <a href="http://www.voidman.com/2009/05/using-wordpress-plugin-api-hack-discuz.html">http://www.voidman.com/2009/05/using-wordpress-plugin-api-hack-discuz.html</a><br /><img alt="linezing" width="1" height="1" src="http://img.tongji.linezing.com/288120/tongji.gif" />]]></content:encoded>
			<wfw:commentRss>http://www.voidman.com/2009/05/using-wordpress-plugin-api-hack-discuz.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>At Reply Mail Notification 1.0 Release</title>
		<link>http://www.voidman.com/2009/04/at-reply-mail-notification-1-release.html</link>
		<comments>http://www.voidman.com/2009/04/at-reply-mail-notification-1-release.html#comments</comments>
		<pubDate>Wed, 15 Apr 2009 11:49:35 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Blog Related]]></category>
		<category><![CDATA[@reply]]></category>
		<category><![CDATA[at reply]]></category>
		<category><![CDATA[mail notification]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.voidman.com/?p=277</guid>
		<description><![CDATA[终于将 At Reply Mail Notification 的后台回复功能加上，这样看起来算是一个插件了。不过没有提供后台插件管理选项，觉得没有这个必要，因为相关设置不多且修改频繁度并不会太高。先上截图： HTML 模版： 实际邮件效果（163邮箱），已经测试过的邮箱包括 gmail, yahoo.com, 163, 126, qq, live mail 后台回复界面： 访客回复界面： 更多详情和下载请点击： at-reply-mail-notification UPDATED at 2010-6-23 修复 WordPress 2.8 版本以后在后台留言管理中无法回复的问题 Related PostsAt Reply Mail Notification 测试贴对 Head META Description 的一些改进WordPress 的 Hook 机制在 Discuz 二次开发中的应用LBS 转 WordPress 不完全记录Wordpress 糟糕的重复评论检测方式让 Wordpress 自动删除 Post Revisions让 Google Sitemaps Generator 可以忽略指定的日志分类Wordpress 分页文章静态化的更优解决方案升级到 [...]]]></description>
			<content:encoded><![CDATA[<p>终于将 <a href="http://www.voidman.com/2009/01/at-reply-mail-notification-test.html">At Reply Mail Notification</a> 的后台回复功能加上，这样看起来算是一个插件了。不过没有提供后台插件管理选项，觉得没有这个必要，因为相关设置不多且修改频繁度并不会太高。先上截图：</p>
<p><strong>HTML 模版：</strong><br />
<a href="http://img.voidman.com/wp/2009/04/mail_template_html.png"><img src="http://img.voidman.com/wp/2009/04/mail_template_html-600x333.png" alt="mail_template_html" title="mail_template_html" width="600" height="333" class="grayborder" /></a><br />
<span id="more-277"></span><br />
<strong>实际邮件效果</strong>（163邮箱），已经测试过的邮箱包括 gmail, yahoo.com, 163, 126, qq, live mail<br />
<a href="http://img.voidman.com/wp/2009/04/mail_html.png"><img src="http://img.voidman.com/wp/2009/04/mail_html-600x432.png" alt="mail_html" title="mail_html" width="600" height="432" class="grayborder" /></a></p>
<p><strong>后台回复界面：</strong><br />
<img src="http://img.voidman.com/wp/2009/04/admin_reply.png" alt="admin_reply" title="admin_reply" width="533" height="70" class="grayborder" /></p>
<p><strong>访客回复界面：</strong><br />
<img src="http://img.voidman.com/wp/2009/04/reply-button.png" alt="vistor_reply" title="vistor_reply" width="533" height="70" class="grayborder" /></p>
<p><strong>更多详情和下载请点击：</strong><br />
<a href="http://code.google.com/p/at-reply-mail-notification/" target="_blank">at-reply-mail-notification</a></p>
<p><strong>UPDATED at 2010-6-23</strong><br />
修复 WordPress 2.8 版本以后在后台留言管理中无法回复的问题</p>
<h4>Related Posts</h4><ul class="related_post"><li><a href="http://www.voidman.com/2009/01/at-reply-mail-notification-test.html" title="At Reply Mail Notification 测试贴">At Reply Mail Notification 测试贴</a></li><li><a href="http://www.voidman.com/2008/03/improve-wp-plugin-head-meta-description.html" title="对 Head META Description 的一些改进">对 Head META Description 的一些改进</a></li><li><a href="http://www.voidman.com/2009/05/using-wordpress-plugin-api-hack-discuz.html" title="WordPress 的 Hook 机制在 Discuz 二次开发中的应用">WordPress 的 Hook 机制在 Discuz 二次开发中的应用</a></li><li><a href="http://www.voidman.com/2009/03/lbs-to-wordpress.html" title="LBS 转 WordPress 不完全记录">LBS 转 WordPress 不完全记录</a></li><li><a href="http://www.voidman.com/2009/01/wordpress-is-using-a-bad-way-to-detect-duplicate-comment.html" title="Wordpress 糟糕的重复评论检测方式">Wordpress 糟糕的重复评论检测方式</a></li><li><a href="http://www.voidman.com/2008/11/automatically-delete-post-revisions.html" title="让 Wordpress 自动删除 Post Revisions">让 Wordpress 自动删除 Post Revisions</a></li><li><a href="http://www.voidman.com/2008/11/google-xml-sitemaps-ignore-the-specified-categories.html" title="让 Google Sitemaps Generator 可以忽略指定的日志分类">让 Google Sitemaps Generator 可以忽略指定的日志分类</a></li><li><a href="http://www.voidman.com/2008/11/the-better-solution-for-static-paged-post.html" title="Wordpress 分页文章静态化的更优解决方案">Wordpress 分页文章静态化的更优解决方案</a></li><li><a href="http://www.voidman.com/2008/07/upgraded-to-wordpress-v26.html" title="升级到 WordPress 2.6">升级到 WordPress 2.6</a></li><li><a href="http://www.voidman.com/2008/03/upgraded-to-wordpress-25-rc1.html" title="升级到 WordPress 2.5 RC1">升级到 WordPress 2.5 RC1</a></li></ul><hr /><a href="http://www.voidman.com">Voidman.com</a> | Link: <a href="http://www.voidman.com/2009/04/at-reply-mail-notification-1-release.html">http://www.voidman.com/2009/04/at-reply-mail-notification-1-release.html</a><br /><img alt="linezing" width="1" height="1" src="http://img.tongji.linezing.com/288120/tongji.gif" />]]></content:encoded>
			<wfw:commentRss>http://www.voidman.com/2009/04/at-reply-mail-notification-1-release.html/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>LBS 转 WordPress 不完全记录</title>
		<link>http://www.voidman.com/2009/03/lbs-to-wordpress.html</link>
		<comments>http://www.voidman.com/2009/03/lbs-to-wordpress.html#comments</comments>
		<pubDate>Sun, 22 Mar 2009 04:04:27 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Blog Related]]></category>
		<category><![CDATA[iis rewrite]]></category>
		<category><![CDATA[lbs]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.voidman.com/?p=250</guid>
		<description><![CDATA[<p class="page-links"><strong>Pages:</strong> 1 <a href="http://www.voidman.com/2009/03/lbs-to-wordpress-2.html">2</a></p>早就答应 Cure 要帮他把博客从 LBS 转到 WordPress，事实上从他的闪光花园开始长了杂草之后，我就一直鼓动他转到 WordPress 下。或许是一直借口太忙了又或是自我标榜的“完美主义”在作怪，总之断断续续拖拖拉拉，从一月份一直到前些日子才将闪光花园的 LBS 主题改写成 WordPress 版本的，基本上了保留了原貌，用 Cure 的话说和之前没什么两样。尝试用了下 CSS Sprite，把一大堆不同类的背景图片弄到一起看起来是个失误，不过暂时也懒得改了。 ACCESS TO MySQL 数据转换费了一些周折。找了个工具叫 Bullzip MS Access to MySQL，在 XP 下却不能正常使用，提示“Error in function 'cmdNext_Click'”之类的错误。官方论坛有人说是 ADO 不存在的缘故，不过折腾了半天问题照旧。后来在安装了 SQL SERVER 的WIN2003系统下成功将数据 Dump 成 SQL 文本，可中文却是乱码，崩溃。最后还是用了月光的转换软件搞定，不过月光的软件不会生成创建表结构的语句，所以还是两者结合了一下，才将 LBS 数据转到 MySQL 下。 LBS 数据导入到 WordPress 表中 根据需要，只转换了 blog_article、blog_category、blog_comment 三个表的数据，然后将数据导入 WordPress 表中： # 导入日志 INSERT [...]]]></description>
			<content:encoded><![CDATA[<p class="page-links"><strong>Pages:</strong> 1 <a href="http://www.voidman.com/2009/03/lbs-to-wordpress-2.html">2</a></p><p>早就答应 Cure 要帮他把博客从 LBS 转到 WordPress，事实上从他的<a href="http://www-s-isle.com/blog/">闪光花园</a>开始长了杂草之后，我就一直鼓动他转到 WordPress 下。或许是一直借口太忙了又或是自我标榜的“完美主义”在作怪，总之断断续续拖拖拉拉，从一月份一直到前些日子才将闪光花园的 LBS 主题改写成 WordPress 版本的，基本上了保留了原貌，用 Cure 的话说和之前没什么两样。尝试用了下 CSS Sprite，把一大堆不同类的背景图片弄到一起看起来是个失误，不过暂时也懒得改了。</p>
<p><strong>ACCESS TO MySQL</strong><br />
数据转换费了一些周折。找了个工具叫 Bullzip MS Access to MySQL，在 XP 下却不能正常使用，提示“Error in function 'cmdNext_Click'”之类的错误。官方论坛<a href="http://www.bullzip.com/phpBB/viewtopic.php?t=6338">有人说</a>是 ADO 不存在的缘故，不过折腾了半天问题照旧。后来在安装了 SQL SERVER 的WIN2003系统下成功将数据 Dump 成 SQL 文本，可中文却是乱码，崩溃。最后还是用了<a href="http://www.williamlong.info">月光</a>的<a href="http://www.williamlong.info/archives/1057.html">转换软件</a>搞定，不过月光的软件不会生成创建表结构的语句，所以还是两者结合了一下，才将 LBS 数据转到 MySQL 下。<br />
<span id="more-250"></span><br />
<strong>LBS 数据导入到 WordPress 表中</strong><br />
根据需要，只转换了 blog_article、blog_category、blog_comment 三个表的数据，然后将数据导入 WordPress 表中：</p>

<div class="wp_syntax"><pre class="mysql"><span style="color: #008200; font-style: italic;"># 导入日志</span>
<span style="color: #0000FF; ">INSERT</span> <span style="color: #0000FF; ">INTO</span>  wp_posts <span style="color: #000;">&#40;</span>ID, post_author, post_date, post_content, post_title, post_status, post_modified<span style="color: #000;">&#41;</span>
<span style="color: #0000FF; ">SELECT</span> log_id, <span style="color: #840000;">2</span>, log_postTime, <span style="color: #0000FF; ">CONCAT</span><span style="color: #000;">&#40;</span>log_content0, <span style="color: #0000FF; ">CHAR</span><span style="color: #000;">&#40;</span><span style="color: #840000;">13</span><span style="color: #000;">&#41;</span>, <span style="color: #FF00FF;">'&lt;!--more--&gt;'</span>, <span style="color: #0000FF; ">CHAR</span><span style="color: #000;">&#40;</span><span style="color: #840000;">13</span><span style="color: #000;">&#41;</span>, log_content1<span style="color: #000;">&#41;</span>, log_title, <span style="color: #FF00FF;">'publish'</span>, log_postTime
<span style="color: #0000FF; ">FROM</span> blog_article
&nbsp;
<span style="color: #008200; font-style: italic;"># 导入评论</span>
<span style="color: #0000FF; ">INSERT</span> <span style="color: #0000FF; ">INTO</span> wp_comments <span style="color: #000;">&#40;</span>comment_ID, comment_post_ID, comment_author, comment_author_email, comment_author_url, comment_author_IP, comment_date, comment_content, comment_approved, comment_agent, comment_type, comment_parent, user_id <span style="color: #000;">&#41;</span>
<span style="color: #0000FF; ">SELECT</span> comm_id, log_id, comm_author, <span style="color: #FF00FF;">''</span>, <span style="color: #FF00FF;">''</span>, comm_ip, comm_postTime, comm_content, <span style="color: #840000;">1</span>, <span style="color: #FF00FF;">''</span>, <span style="color: #FF00FF;">''</span>, <span style="color: #840000;">0</span>, <span style="color: #840000;">0</span>
<span style="color: #0000FF; ">FROM</span> blog_comment
&nbsp;
<span style="color: #008200; font-style: italic;"># 更新日志的评论数</span>
<span style="color: #0000FF; ">UPDATE</span> wp_posts p, <span style="color: #000;">&#40;</span>SELECTcomment_post_ID AS pid, COUNT<span style="color: #000;">&#40;</span>*<span style="color: #000;">&#41;</span> AS counts <span style="color: #0000FF; ">FROM</span> wp_comments <span style="color: #0000FF; ">GROUP</span> <span style="color: #0000FF; ">BY</span> comment_post_ID<span style="color: #000;">&#41;</span> c
<span style="color: #0000FF; ">SET</span> p.comment_count = c.counts
<span style="color: #0000FF; ">WHERE</span> p.ID = c.pid
&nbsp;
<span style="color: #008200; font-style: italic;"># 导入日志类别</span>
<span style="color: #008200; font-style: italic;"># 类别不多，直接在后台里手工添加了</span>
&nbsp;
<span style="color: #008200; font-style: italic;"># 更新新旧类别对应关系</span>
<span style="color: #008200; font-style: italic;"># 在 blog_category 增加 cat_newid 字段，将类别的新ID填入此字段，同样手工操作了</span>
&nbsp;
<span style="color: #008200; font-style: italic;"># 导入日志与分类关系</span>
<span style="color: #0000FF; ">INSERT</span> <span style="color: #0000FF; ">INTO</span> wp_term_relationships <span style="color: #000;">&#40;</span>object_id, term_taxonomy_id<span style="color: #000;">&#41;</span>
<span style="color: #0000FF; ">SELECT</span> log_id, c.cat_newid
<span style="color: #0000FF; ">FROM</span> blog_article a, blog_category c
<span style="color: #0000FF; ">WHERE</span> a.log_catID = c.cat_id
&nbsp;
<span style="color: #008200; font-style: italic;"># 更新分类下日志数</span>
<span style="color: #0000FF; ">UPDATE</span> wp_term_taxonomy t, <span style="color: #000;">&#40;</span><span style="color: #0000FF; ">SELECT</span> term_taxonomy_id, count<span style="color: #000;">&#40;</span>*<span style="color: #000;">&#41;</span> AS counts <span style="color: #0000FF; ">FROM</span> wp_term_relationships <span style="color: #0000FF; ">GROUP</span> <span style="color: #0000FF; ">BY</span> term_taxonomy_id<span style="color: #000;">&#41;</span> r
<span style="color: #0000FF; ">SET</span> t.count = r.counts
<span style="color: #0000FF; ">WHERE</span> t.term_taxonomy_id = r.term_taxonomy_id</pre></div>

<p><strong>日志和评论内容UBB代码转换</strong><br />
Cure 的日志基本上只用了 URL, FONT, SIZE, CENTER, IMG 这几个 UBB 代码，所以干脆将数据导出到SQL文本中，直接用 Editplus 的正则替换功能将UBB 代码转成了 HTML 。</p>
<h4>Related Posts</h4><ul class="related_post"><li><a href="http://www.voidman.com/2009/05/using-wordpress-plugin-api-hack-discuz.html" title="WordPress 的 Hook 机制在 Discuz 二次开发中的应用">WordPress 的 Hook 机制在 Discuz 二次开发中的应用</a></li><li><a href="http://www.voidman.com/2009/04/at-reply-mail-notification-1-release.html" title="At Reply Mail Notification 1.0 Release">At Reply Mail Notification 1.0 Release</a></li><li><a href="http://www.voidman.com/2009/01/wordpress-is-using-a-bad-way-to-detect-duplicate-comment.html" title="Wordpress 糟糕的重复评论检测方式">Wordpress 糟糕的重复评论检测方式</a></li><li><a href="http://www.voidman.com/2009/01/at-reply-mail-notification-test.html" title="At Reply Mail Notification 测试贴">At Reply Mail Notification 测试贴</a></li><li><a href="http://www.voidman.com/2008/11/automatically-delete-post-revisions.html" title="让 Wordpress 自动删除 Post Revisions">让 Wordpress 自动删除 Post Revisions</a></li><li><a href="http://www.voidman.com/2008/11/google-xml-sitemaps-ignore-the-specified-categories.html" title="让 Google Sitemaps Generator 可以忽略指定的日志分类">让 Google Sitemaps Generator 可以忽略指定的日志分类</a></li><li><a href="http://www.voidman.com/2008/11/the-better-solution-for-static-paged-post.html" title="Wordpress 分页文章静态化的更优解决方案">Wordpress 分页文章静态化的更优解决方案</a></li><li><a href="http://www.voidman.com/2008/07/upgraded-to-wordpress-v26.html" title="升级到 WordPress 2.6">升级到 WordPress 2.6</a></li><li><a href="http://www.voidman.com/2008/03/upgraded-to-wordpress-25-rc1.html" title="升级到 WordPress 2.5 RC1">升级到 WordPress 2.5 RC1</a></li><li><a href="http://www.voidman.com/2008/03/wordpress-theme-wpcandy-remix.html" title="WordPress Theme WPCandy Remix">WordPress Theme WPCandy Remix</a></li></ul><hr /><a href="http://www.voidman.com">Voidman.com</a> | Link: <a href="http://www.voidman.com/2009/03/lbs-to-wordpress.html">http://www.voidman.com/2009/03/lbs-to-wordpress.html</a><br /><img alt="linezing" width="1" height="1" src="http://img.tongji.linezing.com/288120/tongji.gif" />]]></content:encoded>
			<wfw:commentRss>http://www.voidman.com/2009/03/lbs-to-wordpress.html/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>WordPress 糟糕的重复评论检测方式</title>
		<link>http://www.voidman.com/2009/01/wordpress-is-using-a-bad-way-to-detect-duplicate-comment.html</link>
		<comments>http://www.voidman.com/2009/01/wordpress-is-using-a-bad-way-to-detect-duplicate-comment.html#comments</comments>
		<pubDate>Thu, 22 Jan 2009 14:13:49 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Blog Related]]></category>
		<category><![CDATA[comment]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[重复评论]]></category>

		<guid isPermaLink="false">http://www.voidman.com/?p=231</guid>
		<description><![CDATA[去旧空间清理文件时，用 FTP 拉下一大堆 mysql slow queries 日志。由于我的博客平时几乎没什么人来访问，所以我也没怎么去关心是否存在 mysql slow queries。看了下日志，发现绝大部分 slow query 都是由 WordPress 的重复评论检测造成成的： 没想到居然直接用 Text 类型的 comment_content 字段来判断评论重复，太衰了。开始还怀疑是不是日志搞错了，于是找到相应的代码确认： // Simple duplicate check // expected_slashed ($comment_post_ID, $comment_author, $comment_author_email, $comment_content) $dupe = &#34;SELECT comment_ID FROM $wpdb-&#62;comments WHERE comment_post_ID = '$comment_post_ID' AND ( comment_author = '$comment_author' &#34;; if &#40; $comment_author_email &#41; $dupe .= &#34;OR comment_author_email = [...]]]></description>
			<content:encoded><![CDATA[<p>去旧空间清理文件时，用 FTP 拉下一大堆 mysql slow queries 日志。由于我的博客平时几乎没什么人来访问，所以我也没怎么去关心是否存在 mysql slow queries。看了下日志，发现绝大部分 slow query 都是由 WordPress 的重复评论检测造成成的：</p>
<p class="imgwrap">
<img src="http://img.voidman.com/wp/2009/01/wp_comment_mysql_slow_queries.png" alt="wp_comment_mysql_slow_queries" class="grayborder" style="padding: 2px"/>
</p>
<p>没想到居然直接用 Text 类型的 comment_content 字段来判断评论重复，太衰了。开始还怀疑是不是日志搞错了，于是找到相应的代码确认：<span id="more-231"></span></p>

<div class="wp_syntax"><pre class="php"><span style="color: #008000; font-style: italic;">// Simple duplicate check</span>
<span style="color: #008000; font-style: italic;">// expected_slashed ($comment_post_ID, $comment_author, $comment_author_email, $comment_content)</span>
<span style="color: #008080;">$dupe</span> = <span style="color: #ff00ff;">&quot;SELECT comment_ID FROM $wpdb-&gt;comments WHERE comment_post_ID = '$comment_post_ID' AND ( comment_author = '$comment_author' &quot;</span>;
<span style="color: blue;">if</span> <span style="color: #800000;">&#40;</span> <span style="color: #008080;">$comment_author_email</span> <span style="color: #800000;">&#41;</span>
  <span style="color: #008080;">$dupe</span> .= <span style="color: #ff00ff;">&quot;OR comment_author_email = '$comment_author_email' &quot;</span>;
<span style="color: #008080;">$dupe</span> .= <span style="color: #ff00ff;">&quot;) AND comment_content = '$comment_content' LIMIT 1&quot;</span>;
<span style="color: blue;">if</span> <span style="color: #800000;">&#40;</span> <span style="color: #008080;">$wpdb</span>-&gt;<span style="color: #006600;">get_var</span><span style="color: #800000;">&#40;</span><span style="color: #008080;">$dupe</span><span style="color: #800000;">&#41;</span> <span style="color: #800000;">&#41;</span> <span style="color: #800000;">&#123;</span>
  <span style="color: blue;">if</span> <span style="color: #800000;">&#40;</span> <span style="color: #ff0000;">defined</span><span style="color: #800000;">&#40;</span><span style="color: #ff00ff;">'DOING_AJAX'</span><span style="color: #800000;">&#41;</span> <span style="color: #800000;">&#41;</span>
    <span style="color: blue;">die</span><span style="color: #800000;">&#40;</span> __<span style="color: #800000;">&#40;</span><span style="color: #ff00ff;">'Duplicate comment detected; it looks as though you<span style="">\'</span>ve already said that!'</span><span style="color: #800000;">&#41;</span> <span style="color: #800000;">&#41;</span>;
&nbsp;
  wp_die<span style="color: #800000;">&#40;</span> __<span style="color: #800000;">&#40;</span><span style="color: #ff00ff;">'Duplicate comment detected; it looks as though you<span style="">\'</span>ve already said that!'</span><span style="color: #800000;">&#41;</span> <span style="color: #800000;">&#41;</span>;
<span style="color: #800000;">&#125;</span>
<span style="color: #008000; font-style: italic;">// 上述代码位于 wp-includes/comment.php 文件的 wp_allow_comment 函数中</span></pre></div>

<p>有点奇怪 WP 为什么不考虑加个 comment_hash 字段，将评论内容 hash 一下，然后建个索引，那检测速度肯定杠杠滴。</p>
<h4>Related Posts</h4><ul class="related_post"><li><a href="http://www.voidman.com/2009/05/using-wordpress-plugin-api-hack-discuz.html" title="WordPress 的 Hook 机制在 Discuz 二次开发中的应用">WordPress 的 Hook 机制在 Discuz 二次开发中的应用</a></li><li><a href="http://www.voidman.com/2009/04/at-reply-mail-notification-1-release.html" title="At Reply Mail Notification 1.0 Release">At Reply Mail Notification 1.0 Release</a></li><li><a href="http://www.voidman.com/2009/03/lbs-to-wordpress.html" title="LBS 转 WordPress 不完全记录">LBS 转 WordPress 不完全记录</a></li><li><a href="http://www.voidman.com/2009/01/at-reply-mail-notification-test.html" title="At Reply Mail Notification 测试贴">At Reply Mail Notification 测试贴</a></li><li><a href="http://www.voidman.com/2008/11/automatically-delete-post-revisions.html" title="让 Wordpress 自动删除 Post Revisions">让 Wordpress 自动删除 Post Revisions</a></li><li><a href="http://www.voidman.com/2008/11/google-xml-sitemaps-ignore-the-specified-categories.html" title="让 Google Sitemaps Generator 可以忽略指定的日志分类">让 Google Sitemaps Generator 可以忽略指定的日志分类</a></li><li><a href="http://www.voidman.com/2008/11/the-better-solution-for-static-paged-post.html" title="Wordpress 分页文章静态化的更优解决方案">Wordpress 分页文章静态化的更优解决方案</a></li><li><a href="http://www.voidman.com/2008/07/upgraded-to-wordpress-v26.html" title="升级到 WordPress 2.6">升级到 WordPress 2.6</a></li><li><a href="http://www.voidman.com/2008/03/upgraded-to-wordpress-25-rc1.html" title="升级到 WordPress 2.5 RC1">升级到 WordPress 2.5 RC1</a></li><li><a href="http://www.voidman.com/2008/03/wordpress-theme-wpcandy-remix.html" title="WordPress Theme WPCandy Remix">WordPress Theme WPCandy Remix</a></li></ul><hr /><a href="http://www.voidman.com">Voidman.com</a> | Link: <a href="http://www.voidman.com/2009/01/wordpress-is-using-a-bad-way-to-detect-duplicate-comment.html">http://www.voidman.com/2009/01/wordpress-is-using-a-bad-way-to-detect-duplicate-comment.html</a><br /><img alt="linezing" width="1" height="1" src="http://img.tongji.linezing.com/288120/tongji.gif" />]]></content:encoded>
			<wfw:commentRss>http://www.voidman.com/2009/01/wordpress-is-using-a-bad-way-to-detect-duplicate-comment.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>At Reply Mail Notification 测试贴</title>
		<link>http://www.voidman.com/2009/01/at-reply-mail-notification-test.html</link>
		<comments>http://www.voidman.com/2009/01/at-reply-mail-notification-test.html#comments</comments>
		<pubDate>Mon, 19 Jan 2009 01:40:45 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Blog Related]]></category>
		<category><![CDATA[@reply]]></category>
		<category><![CDATA[at reply]]></category>
		<category><![CDATA[mail notification]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.voidman.com/?p=228</guid>
		<description><![CDATA[想给博客加上访客留言被回复时邮件通知留言者的功能，本不想折腾，只不过试用了几个插件，都觉得不尽满意，便自己写了一个，先实现了几个功能： 访客可以针对每篇日志选择是否接收邮件通知 访客可以针对每篇日志选择接收何种评论通知 访客可以点击邮件底部的链接取消邮件通知 对于使用 @+留言者 形式的回复暂未作邮件通知，需点击留言者名称右边的小图标 回复。回复通知只对即日起的新留言有效。 欢迎在此留言，灌水。 Related PostsAt Reply Mail Notification 1.0 Release对 Head META Description 的一些改进WordPress 的 Hook 机制在 Discuz 二次开发中的应用LBS 转 WordPress 不完全记录Wordpress 糟糕的重复评论检测方式让 Wordpress 自动删除 Post Revisions让 Google Sitemaps Generator 可以忽略指定的日志分类Wordpress 分页文章静态化的更优解决方案升级到 WordPress 2.6升级到 WordPress 2.5 RC1Voidman.com &#124; Link: http://www.voidman.com/2009/01/at-reply-mail-notification-test.html]]></description>
			<content:encoded><![CDATA[<p>想给博客加上访客留言被回复时邮件通知留言者的功能，本不想折腾，只不过试用了几个插件，都觉得不尽满意，便自己写了一个，先实现了几个功能：</p>
<ul>
<li>访客可以针对每篇日志选择是否接收邮件通知</li>
<li>访客可以针对每篇日志选择接收何种评论通知</li>
<li>访客可以点击邮件底部的链接取消邮件通知</li>
</ul>
<p>对于使用 @+留言者 形式的回复暂未作邮件通知，需点击留言者名称右边的小图标 <img src="http://www.voidman.com/wp-content/themes/wpcandy/images/reply.png" alt="reply icon" /> 回复。回复通知只对即日起的新留言有效。</p>
<p>欢迎在此留言，灌水。</p>
<h4>Related Posts</h4><ul class="related_post"><li><a href="http://www.voidman.com/2009/04/at-reply-mail-notification-1-release.html" title="At Reply Mail Notification 1.0 Release">At Reply Mail Notification 1.0 Release</a></li><li><a href="http://www.voidman.com/2008/03/improve-wp-plugin-head-meta-description.html" title="对 Head META Description 的一些改进">对 Head META Description 的一些改进</a></li><li><a href="http://www.voidman.com/2009/05/using-wordpress-plugin-api-hack-discuz.html" title="WordPress 的 Hook 机制在 Discuz 二次开发中的应用">WordPress 的 Hook 机制在 Discuz 二次开发中的应用</a></li><li><a href="http://www.voidman.com/2009/03/lbs-to-wordpress.html" title="LBS 转 WordPress 不完全记录">LBS 转 WordPress 不完全记录</a></li><li><a href="http://www.voidman.com/2009/01/wordpress-is-using-a-bad-way-to-detect-duplicate-comment.html" title="Wordpress 糟糕的重复评论检测方式">Wordpress 糟糕的重复评论检测方式</a></li><li><a href="http://www.voidman.com/2008/11/automatically-delete-post-revisions.html" title="让 Wordpress 自动删除 Post Revisions">让 Wordpress 自动删除 Post Revisions</a></li><li><a href="http://www.voidman.com/2008/11/google-xml-sitemaps-ignore-the-specified-categories.html" title="让 Google Sitemaps Generator 可以忽略指定的日志分类">让 Google Sitemaps Generator 可以忽略指定的日志分类</a></li><li><a href="http://www.voidman.com/2008/11/the-better-solution-for-static-paged-post.html" title="Wordpress 分页文章静态化的更优解决方案">Wordpress 分页文章静态化的更优解决方案</a></li><li><a href="http://www.voidman.com/2008/07/upgraded-to-wordpress-v26.html" title="升级到 WordPress 2.6">升级到 WordPress 2.6</a></li><li><a href="http://www.voidman.com/2008/03/upgraded-to-wordpress-25-rc1.html" title="升级到 WordPress 2.5 RC1">升级到 WordPress 2.5 RC1</a></li></ul><hr /><a href="http://www.voidman.com">Voidman.com</a> | Link: <a href="http://www.voidman.com/2009/01/at-reply-mail-notification-test.html">http://www.voidman.com/2009/01/at-reply-mail-notification-test.html</a><br /><img alt="linezing" width="1" height="1" src="http://img.tongji.linezing.com/288120/tongji.gif" />]]></content:encoded>
			<wfw:commentRss>http://www.voidman.com/2009/01/at-reply-mail-notification-test.html/feed</wfw:commentRss>
		<slash:comments>28</slash:comments>
		</item>
		<item>
		<title>让 WordPress 自动删除 Post Revisions</title>
		<link>http://www.voidman.com/2008/11/automatically-delete-post-revisions.html</link>
		<comments>http://www.voidman.com/2008/11/automatically-delete-post-revisions.html#comments</comments>
		<pubDate>Tue, 18 Nov 2008 01:00:52 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Blog Related]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[revisions]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WP_Cron]]></category>
		<category><![CDATA[计划任务]]></category>

		<guid isPermaLink="false">http://www.voidman.com/?p=188</guid>
		<description><![CDATA[貌似在 wp-config.php 中加入 define(’WP_POST_REVISIONS’, false); 来禁用 WordPress 的日志修订功能，post revision 还是会产生。gohsy 同学写了个插件 Revision Manager 来清理 post revision，不过个人觉得手动清理还是不够方便，决定利用 WordPress 的计划任务功能(WP_Cron)偷偷懒。 不想为了这小小的功能而多添加一个插件，所以在主题目录下的 functions.php 文件添加了以下代码： function delete_post_revisions&#40;&#41; &#123; global $wpdb; &#160; // Also need to delete the post meta and term relationships $wpdb-&#62;query&#40;&#34;DELETE FROM {$wpdb-&#62;postmeta} WHERE post_id IN (SELECT ID FROM {$wpdb-&#62;posts} WHERE post_type = 'revision')&#34;&#41;; $wpdb-&#62;query&#40;&#34;DELETE FROM {$wpdb-&#62;term_relationships} [...]]]></description>
			<content:encoded><![CDATA[<p>貌似在 <code>wp-config.php</code> 中加入 <code>define(’WP_POST_REVISIONS’, false);</code> 来禁用 WordPress 的日志修订功能，post revision 还是会产生。<a href="http://blog.gohsy.com/" rel="external nofollow">gohsy</a> 同学写了个插件 <a href="http://blog.gohsy.com/topics/delete-revision-plugin.html" rel="external nofollow">Revision Manager</a> 来清理 post revision，不过个人觉得手动清理还是不够方便，决定利用 WordPress 的计划任务功能(WP_Cron)偷偷懒。</p>
<p>不想为了这小小的功能而多添加一个插件，所以在主题目录下的 <code>functions.php</code> 文件添加了以下代码：</p>

<div class="wp_syntax"><pre class="php"><span style="color: blue;">function</span> delete_post_revisions<span style="color: #800000;">&#40;</span><span style="color: #800000;">&#41;</span> <span style="color: #800000;">&#123;</span>
  <span style="color: blue;">global</span> <span style="color: #008080;">$wpdb</span>;
&nbsp;
  <span style="color: #008000; font-style: italic;">// Also need to delete the post meta and term relationships</span>
  <span style="color: #008080;">$wpdb</span>-&gt;<span style="color: #006600;">query</span><span style="color: #800000;">&#40;</span><span style="color: #ff00ff;">&quot;DELETE FROM {$wpdb-&gt;postmeta} WHERE post_id IN (SELECT ID FROM {$wpdb-&gt;posts} WHERE post_type = 'revision')&quot;</span><span style="color: #800000;">&#41;</span>;
  <span style="color: #008080;">$wpdb</span>-&gt;<span style="color: #006600;">query</span><span style="color: #800000;">&#40;</span><span style="color: #ff00ff;">&quot;DELETE FROM {$wpdb-&gt;term_relationships} WHERE object_id IN (SELECT ID FROM {$wpdb-&gt;posts} WHERE post_type = 'revision')&quot;</span><span style="color: #800000;">&#41;</span>;
&nbsp;
  <span style="color: #008000; font-style: italic;">// Delete the post revisions</span>
  <span style="color: #008080;">$wpdb</span>-&gt;<span style="color: #006600;">query</span><span style="color: #800000;">&#40;</span><span style="color: #ff00ff;">&quot;DELETE FROM {$wpdb-&gt;posts} WHERE post_type = 'revision'&quot;</span><span style="color: #800000;">&#41;</span>;
<span style="color: #800000;">&#125;</span>
&nbsp;
<span style="color: #008000; font-style: italic;">// Register the event</span>
add_action<span style="color: #800000;">&#40;</span><span style="color: #ff00ff;">'delete_post_revisions_event'</span>, <span style="color: #ff00ff;">'delete_post_revisions'</span><span style="color: #800000;">&#41;</span>;
<span style="color: blue;">if</span> <span style="color: #800000;">&#40;</span>!wp_next_scheduled<span style="color: #800000;">&#40;</span><span style="color: #ff00ff;">'delete_post_revisions_event'</span><span style="color: #800000;">&#41;</span><span style="color: #800000;">&#41;</span> <span style="color: #800000;">&#123;</span>
  wp_schedule_event<span style="color: #800000;">&#40;</span><span style="color: #ff0000;">time</span><span style="color: #800000;">&#40;</span><span style="color: #800000;">&#41;</span>, <span style="color: #ff00ff;">'daily'</span>, <span style="color: #ff00ff;">'delete_post_revisions_event'</span><span style="color: #800000;">&#41;</span>;
<span style="color: #800000;">&#125;</span></pre></div>

<p><span id="more-188"></span><br />
这样 WordPress 每天会自动删除 post revision (当然得在有人访问的前提下)。其实每天运行一次也有些过于频繁了，可以将时间间隔设置得更长一些，譬如一周或者二周甚至一个月。不过 WordPress 的 Cron API 本身只提供了 hourly, daily 两个选项，所以需要自己手工添加一些运行时间间隔选项。在刚才添加的代码<strong>之前</strong>添加以下代码，</p>

<div class="wp_syntax"><pre class="php"><span style="color: blue;">function</span> add_schedule_options<span style="color: #800000;">&#40;</span><span style="color: #008080;">$schedules</span><span style="color: #800000;">&#41;</span> <span style="color: #800000;">&#123;</span>
  <span style="color: #008080;">$custom_schedules</span> = <span style="color: blue;">array</span><span style="color: #800000;">&#40;</span>
    <span style="color: #ff00ff;">'weekly'</span> =&gt; <span style="color: blue;">array</span><span style="color: #800000;">&#40;</span> <span style="color: #ff00ff;">'interval'</span> =&gt; <span style="color: #800080;">604800</span>, <span style="color: #ff00ff;">'display'</span> =&gt; __<span style="color: #800000;">&#40;</span><span style="color: #ff00ff;">'Once Weekly'</span><span style="color: #800000;">&#41;</span> <span style="color: #800000;">&#41;</span>, 
    <span style="color: #ff00ff;">'fortnightly'</span> =&gt; <span style="color: blue;">array</span><span style="color: #800000;">&#40;</span> <span style="color: #ff00ff;">'interval'</span> =&gt; <span style="color: #800080;">1209600</span>, <span style="color: #ff00ff;">'display'</span> =&gt; __<span style="color: #800000;">&#40;</span><span style="color: #ff00ff;">'Once Fortnightly'</span><span style="color: #800000;">&#41;</span> <span style="color: #800000;">&#41;</span>, 
    <span style="color: #ff00ff;">'monthly'</span> =&gt; <span style="color: blue;">array</span><span style="color: #800000;">&#40;</span> <span style="color: #ff00ff;">'interval'</span> =&gt; <span style="color: #800080;">2592000</span>, <span style="color: #ff00ff;">'display'</span> =&gt; __<span style="color: #800000;">&#40;</span><span style="color: #ff00ff;">'Once Monthly'</span><span style="color: #800000;">&#41;</span> <span style="color: #800000;">&#41;</span>, 
  <span style="color: #800000;">&#41;</span>;
&nbsp;
  <span style="color: blue;">return</span> <span style="color: #ff0000;">array_merge</span><span style="color: #800000;">&#40;</span><span style="color: #008080;">$custom_schedules</span>, <span style="color: #008080;">$schedules</span><span style="color: #800000;">&#41;</span>;
<span style="color: #800000;">&#125;</span>
add_filter<span style="color: #800000;">&#40;</span><span style="color: #ff00ff;">'cron_schedules'</span>, <span style="color: #ff00ff;">'add_schedule_options'</span><span style="color: #800000;">&#41;</span>;</pre></div>

<p>然后把 <code>wp_schedule_event</code> 函数的第二个参数值 daily 改成 weekly 或  fortnightly 或 monthly 即可。</p>
<h4>Related Posts</h4><ul class="related_post"><li><a href="http://www.voidman.com/2009/05/using-wordpress-plugin-api-hack-discuz.html" title="WordPress 的 Hook 机制在 Discuz 二次开发中的应用">WordPress 的 Hook 机制在 Discuz 二次开发中的应用</a></li><li><a href="http://www.voidman.com/2009/04/at-reply-mail-notification-1-release.html" title="At Reply Mail Notification 1.0 Release">At Reply Mail Notification 1.0 Release</a></li><li><a href="http://www.voidman.com/2009/03/lbs-to-wordpress.html" title="LBS 转 WordPress 不完全记录">LBS 转 WordPress 不完全记录</a></li><li><a href="http://www.voidman.com/2009/01/wordpress-is-using-a-bad-way-to-detect-duplicate-comment.html" title="Wordpress 糟糕的重复评论检测方式">Wordpress 糟糕的重复评论检测方式</a></li><li><a href="http://www.voidman.com/2009/01/at-reply-mail-notification-test.html" title="At Reply Mail Notification 测试贴">At Reply Mail Notification 测试贴</a></li><li><a href="http://www.voidman.com/2008/11/google-xml-sitemaps-ignore-the-specified-categories.html" title="让 Google Sitemaps Generator 可以忽略指定的日志分类">让 Google Sitemaps Generator 可以忽略指定的日志分类</a></li><li><a href="http://www.voidman.com/2008/11/the-better-solution-for-static-paged-post.html" title="Wordpress 分页文章静态化的更优解决方案">Wordpress 分页文章静态化的更优解决方案</a></li><li><a href="http://www.voidman.com/2008/07/upgraded-to-wordpress-v26.html" title="升级到 WordPress 2.6">升级到 WordPress 2.6</a></li><li><a href="http://www.voidman.com/2008/03/upgraded-to-wordpress-25-rc1.html" title="升级到 WordPress 2.5 RC1">升级到 WordPress 2.5 RC1</a></li><li><a href="http://www.voidman.com/2008/03/wordpress-theme-wpcandy-remix.html" title="WordPress Theme WPCandy Remix">WordPress Theme WPCandy Remix</a></li></ul><hr /><a href="http://www.voidman.com">Voidman.com</a> | Link: <a href="http://www.voidman.com/2008/11/automatically-delete-post-revisions.html">http://www.voidman.com/2008/11/automatically-delete-post-revisions.html</a><br /><img alt="linezing" width="1" height="1" src="http://img.tongji.linezing.com/288120/tongji.gif" />]]></content:encoded>
			<wfw:commentRss>http://www.voidman.com/2008/11/automatically-delete-post-revisions.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>让 Google Sitemaps Generator 可以忽略指定的日志分类</title>
		<link>http://www.voidman.com/2008/11/google-xml-sitemaps-ignore-the-specified-categories.html</link>
		<comments>http://www.voidman.com/2008/11/google-xml-sitemaps-ignore-the-specified-categories.html#comments</comments>
		<pubDate>Sat, 15 Nov 2008 12:38:18 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Blog Related]]></category>
		<category><![CDATA[Google Sitemaps Generator]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.voidman.com/?p=186</guid>
		<description><![CDATA[在之前使用 HemingwayEx 主题的时候我把一些只有半句或几句话的日志移动到了 asides 分类，而现在我不想让 Google Sitemaps Generator 插件生成 sitemap 的时候包括这些日志，也许只有我才会有这样奇怪的需求 。 可 Google XML Sitemaps 只能忽略指定的日志或页面，而不能忽略整个分类，所以只能自己动手了。 1. 打开插件目录下的 sitemap-core.php 文件，找到： $where.=&#34; AND post_password='' ORDER BY post_modified DESC&#34;; &#160; $sql .= $where; 修改成： $where.=&#34; AND post_password='' ORDER BY post_modified DESC&#34;; $where = apply_filters&#40;'sitemap_exclude_categories', $where&#41;; $sql .= $where; 2. 打开主题目录下的 functions.php 文件，添加一下代码： function sitemap_exclude_categories&#40;$where&#41; &#123; global [...]]]></description>
			<content:encoded><![CDATA[<p>在之前使用 <a href="http://nalinmakar.com/hemingwayex" rel="external nofollow">HemingwayEx</a> 主题的时候我把一些只有半句或几句话的日志移动到了 asides 分类，而现在我不想让 <a href="http://www.arnebrachhold.de/projects/wordpress-plugins/google-xml-sitemaps-generator/" rel="external nofollow">Google Sitemaps Generator</a> 插件生成 sitemap 的时候包括这些日志，也许只有我才会有这样奇怪的需求 <img src='http://www.voidman.com/wp-includes/images/smilies/icon_eek.gif' alt=':shock:' class='wp-smiley' />   。</p>
<p>可 Google XML Sitemaps 只能忽略指定的日志或页面，而不能忽略整个分类，所以只能自己动手了。</p>
<p>1. 打开插件目录下的 <code>sitemap-core.php</code> 文件，找到：</p>

<div class="wp_syntax"><pre class="php"><span style="color: #008080;">$where</span>.=<span style="color: #ff00ff;">&quot; AND post_password='' ORDER BY post_modified DESC&quot;</span>;
&nbsp;
<span style="color: #008080;">$sql</span> .= <span style="color: #008080;">$where</span>;</pre></div>

<p>修改成：</p>

<div class="wp_syntax"><pre class="php"><span style="color: #008080;">$where</span>.=<span style="color: #ff00ff;">&quot; AND post_password='' ORDER BY post_modified DESC&quot;</span>;
<span style="color: #008080;">$where</span> = apply_filters<span style="color: #800000;">&#40;</span><span style="color: #ff00ff;">'sitemap_exclude_categories'</span>, <span style="color: #008080;">$where</span><span style="color: #800000;">&#41;</span>;
<span style="color: #008080;">$sql</span> .= <span style="color: #008080;">$where</span>;</pre></div>

<p><span id="more-186"></span><br />
2. 打开主题目录下的 <code>functions.php</code> 文件，添加一下代码：</p>

<div class="wp_syntax"><pre class="php"><span style="color: blue;">function</span> sitemap_exclude_categories<span style="color: #800000;">&#40;</span><span style="color: #008080;">$where</span><span style="color: #800000;">&#41;</span> <span style="color: #800000;">&#123;</span>
  <span style="color: blue;">global</span> <span style="color: #008080;">$wpdb</span>;
  <span style="color: #008080;">$cates</span> = <span style="color: blue;">array</span><span style="color: #800000;">&#40;</span><span style="color: #800080;">11</span><span style="color: #800000;">&#41;</span>; <span style="color: #008000; font-style: italic;">// 在这里指定要忽略的类别id，多个类别id用半角逗号分隔</span>
  <span style="color: blue;">if</span> <span style="color: #800000;">&#40;</span><span style="color: #ff0000;">count</span><span style="color: #800000;">&#40;</span><span style="color: #008080;">$cates</span><span style="color: #800000;">&#41;</span> &gt; <span style="color: #800080;">0</span><span style="color: #800000;">&#41;</span> <span style="color: #800000;">&#123;</span>
    <span style="color: #008080;">$table_posts</span> = <span style="color: #008080;">$wpdb</span>-&gt;<span style="color: #006600;">posts</span>;
    <span style="color: #008080;">$exclude</span> = <span style="color: #ff00ff;">&quot;(NOT EXISTS (
      SELECT r.object_id FROM {$wpdb-&gt;term_relationships} r 
      INNER JOIN {$wpdb-&gt;term_taxonomy} t ON r.term_taxonomy_id = t.term_taxonomy_id 
      WHERE t.taxonomy = 'category' AND t.term_id IN (&quot;</span>.<span style="color: #ff0000;">join</span><span style="color: #800000;">&#40;</span><span style="color: #ff00ff;">','</span>, <span style="color: #008080;">$cates</span><span style="color: #800000;">&#41;</span>.<span style="color: #ff00ff;">&quot;) AND r.object_id = `&quot;</span>.<span style="color: #008080;">$table_posts</span>.<span style="color: #ff00ff;">&quot;`.ID
    ))&quot;</span>;
    <span style="color: #008080;">$where</span> = <span style="color: #008080;">$exclude</span>.<span style="color: #ff00ff;">'  AND '</span>.<span style="color: #008080;">$where</span>;
  <span style="color: #800000;">&#125;</span>
&nbsp;
  <span style="color: blue;">return</span> <span style="color: #008080;">$where</span>;
<span style="color: #800000;">&#125;</span>
add_filter<span style="color: #800000;">&#40;</span><span style="color: #ff00ff;">'sitemap_exclude_categories'</span>, <span style="color: #ff00ff;">'sitemap_exclude_categories'</span><span style="color: #800000;">&#41;</span>;</pre></div>

<p>通过 WordPress 自身提供的 Hook API 来实现功能主要是为了尽可能避免过多地修改原插件的代码，以免插件升级时带来麻烦。现在这样升级插件时只要重做第一步就可以了。</p>
<p><strong>UPDATE @ 2009-3-22</strong><br />
最新版本的 Google XML Sitemaps 插件增加了日志分类过滤功能，不过由于它会将被过滤分类下的所有日志 ID 都取出来然后用 NOT IN 来实现过滤，这样在日志数多的情况下效率不高。</p>
<h4>Related Posts</h4><ul class="related_post"><li><a href="http://www.voidman.com/2009/05/using-wordpress-plugin-api-hack-discuz.html" title="WordPress 的 Hook 机制在 Discuz 二次开发中的应用">WordPress 的 Hook 机制在 Discuz 二次开发中的应用</a></li><li><a href="http://www.voidman.com/2009/04/at-reply-mail-notification-1-release.html" title="At Reply Mail Notification 1.0 Release">At Reply Mail Notification 1.0 Release</a></li><li><a href="http://www.voidman.com/2009/03/lbs-to-wordpress.html" title="LBS 转 WordPress 不完全记录">LBS 转 WordPress 不完全记录</a></li><li><a href="http://www.voidman.com/2009/01/wordpress-is-using-a-bad-way-to-detect-duplicate-comment.html" title="Wordpress 糟糕的重复评论检测方式">Wordpress 糟糕的重复评论检测方式</a></li><li><a href="http://www.voidman.com/2009/01/at-reply-mail-notification-test.html" title="At Reply Mail Notification 测试贴">At Reply Mail Notification 测试贴</a></li><li><a href="http://www.voidman.com/2008/11/automatically-delete-post-revisions.html" title="让 Wordpress 自动删除 Post Revisions">让 Wordpress 自动删除 Post Revisions</a></li><li><a href="http://www.voidman.com/2008/11/the-better-solution-for-static-paged-post.html" title="Wordpress 分页文章静态化的更优解决方案">Wordpress 分页文章静态化的更优解决方案</a></li><li><a href="http://www.voidman.com/2008/07/upgraded-to-wordpress-v26.html" title="升级到 WordPress 2.6">升级到 WordPress 2.6</a></li><li><a href="http://www.voidman.com/2008/03/upgraded-to-wordpress-25-rc1.html" title="升级到 WordPress 2.5 RC1">升级到 WordPress 2.5 RC1</a></li><li><a href="http://www.voidman.com/2008/03/wordpress-theme-wpcandy-remix.html" title="WordPress Theme WPCandy Remix">WordPress Theme WPCandy Remix</a></li></ul><hr /><a href="http://www.voidman.com">Voidman.com</a> | Link: <a href="http://www.voidman.com/2008/11/google-xml-sitemaps-ignore-the-specified-categories.html">http://www.voidman.com/2008/11/google-xml-sitemaps-ignore-the-specified-categories.html</a><br /><img alt="linezing" width="1" height="1" src="http://img.tongji.linezing.com/288120/tongji.gif" />]]></content:encoded>
			<wfw:commentRss>http://www.voidman.com/2008/11/google-xml-sitemaps-ignore-the-specified-categories.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>WordPress 分页文章静态化的更优解决方案</title>
		<link>http://www.voidman.com/2008/11/the-better-solution-for-static-paged-post.html</link>
		<comments>http://www.voidman.com/2008/11/the-better-solution-for-static-paged-post.html#comments</comments>
		<pubDate>Wed, 12 Nov 2008 13:19:46 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Blog Related]]></category>
		<category><![CDATA[URL Rewrite]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[分页文章]]></category>
		<category><![CDATA[分页日志]]></category>
		<category><![CDATA[静态化]]></category>

		<guid isPermaLink="false">http://www.voidman.com/?p=179</guid>
		<description><![CDATA[<p class="page-links"><strong>Pages:</strong> 1 <a href="http://www.voidman.com/2008/11/the-better-solution-for-static-paged-post-2.html">2</a></p>之前用比较暴力的方式实现了分页文章的静态化，不过这样一来升级 WordPress 就不太方便了。厌烦了每次升级都要修改源文件，于是利用 WordPress 本身提供的接口实现了更好的解决方案。 以/%year%/%monthnum%/%postname%.html这样的永久链接结构为例： 1. 打开主题目录下的functions.php文件，添加以下代码： // 添加分页处理规则 function add_custom_post_rewrite_rules&#40;$rules&#41; &#123; $custom_rules = array&#40; '([0-9]{4})/([0-9]{1,2})/([^/]+)-([0-9]+)\.html$' =&#62; 'index.php?year=$matches[1]&#38;monthnum=$matches[2]&#38;name=$matches[3]&#38;page=$matches[4]', &#41;; $rules = array_merge&#40;$custom_rules, $rules&#41;; &#160; return $rules; &#125; add_filter&#40;'post_rewrite_rules', 'add_custom_post_rewrite_rules'&#41;; &#160; // 修改分页链接 function my_wp_link_pages&#40;$args = ''&#41; &#123; $args .= &#40;$args ? '&#38;' : ''&#41; . 'echo=0'; $links = wp_link_pages&#40;$args&#41;; $links = preg_replace_callback&#40;'&#124;([0-9]{4}/[0-9]{1,2}/)([^/]+)(\.html)(/)([0-9]+)&#124;', 'custom_page_link', $links&#41;; [...]]]></description>
			<content:encoded><![CDATA[<p class="page-links"><strong>Pages:</strong> 1 <a href="http://www.voidman.com/2008/11/the-better-solution-for-static-paged-post-2.html">2</a></p><p>之前用比较暴力的方式实现了<a href="http://www.voidman.com/2008/03/create-static-html-files-for-paged-post.html">分页文章的静态化</a>，不过这样一来升级 WordPress 就不太方便了。厌烦了每次升级都要修改源文件，于是利用 WordPress 本身提供的接口实现了更好的解决方案。</p>
<p>以<code>/%year%/%monthnum%/%postname%.html</code>这样的永久链接结构为例：</p>
<p>1. 打开主题目录下的<code>functions.php</code>文件，添加以下代码：</p>

<div class="wp_syntax"><pre class="php"><span style="color: #008000; font-style: italic;">// 添加分页处理规则</span>
<span style="color: blue;">function</span> add_custom_post_rewrite_rules<span style="color: #800000;">&#40;</span><span style="color: #008080;">$rules</span><span style="color: #800000;">&#41;</span> <span style="color: #800000;">&#123;</span>
  <span style="color: #008080;">$custom_rules</span> = <span style="color: blue;">array</span><span style="color: #800000;">&#40;</span>
    <span style="color: #ff00ff;">'([0-9]{4})/([0-9]{1,2})/([^/]+)-([0-9]+)<span style="">\.</span>html$'</span> =&gt; <span style="color: #ff00ff;">'index.php?year=$matches[1]&amp;monthnum=$matches[2]&amp;name=$matches[3]&amp;page=$matches[4]'</span>,
  <span style="color: #800000;">&#41;</span>;
  <span style="color: #008080;">$rules</span> = <span style="color: #ff0000;">array_merge</span><span style="color: #800000;">&#40;</span><span style="color: #008080;">$custom_rules</span>, <span style="color: #008080;">$rules</span><span style="color: #800000;">&#41;</span>;
&nbsp;
  <span style="color: blue;">return</span> <span style="color: #008080;">$rules</span>;
<span style="color: #800000;">&#125;</span>
add_filter<span style="color: #800000;">&#40;</span><span style="color: #ff00ff;">'post_rewrite_rules'</span>, <span style="color: #ff00ff;">'add_custom_post_rewrite_rules'</span><span style="color: #800000;">&#41;</span>;
&nbsp;
<span style="color: #008000; font-style: italic;">// 修改分页链接</span>
<span style="color: blue;">function</span> my_wp_link_pages<span style="color: #800000;">&#40;</span><span style="color: #008080;">$args</span> = <span style="color: #ff00ff;">''</span><span style="color: #800000;">&#41;</span> <span style="color: #800000;">&#123;</span>
  <span style="color: #008080;">$args</span> .= <span style="color: #800000;">&#40;</span><span style="color: #008080;">$args</span> ? <span style="color: #ff00ff;">'&amp;'</span> : <span style="color: #ff00ff;">''</span><span style="color: #800000;">&#41;</span> . <span style="color: #ff00ff;">'echo=0'</span>;
  <span style="color: #008080;">$links</span> = wp_link_pages<span style="color: #800000;">&#40;</span><span style="color: #008080;">$args</span><span style="color: #800000;">&#41;</span>;
  <span style="color: #008080;">$links</span> = <span style="color: #ff0000;">preg_replace_callback</span><span style="color: #800000;">&#40;</span><span style="color: #ff00ff;">'|([0-9]{4}/[0-9]{1,2}/)([^/]+)(<span style="">\.</span>html)(/)([0-9]+)|'</span>, <span style="color: #ff00ff;">'custom_page_link'</span>, <span style="color: #008080;">$links</span><span style="color: #800000;">&#41;</span>;
&nbsp;
  <span style="color: blue;">echo</span> <span style="color: #008080;">$links</span>;
<span style="color: #800000;">&#125;</span>
&nbsp;
<span style="color: blue;">function</span> custom_page_link<span style="color: #800000;">&#40;</span><span style="color: #008080;">$matches</span><span style="color: #800000;">&#41;</span> <span style="color: #800000;">&#123;</span>
  <span style="color: blue;">return</span> <span style="color: #008080;">$matches</span><span style="color: #800000;">&#91;</span><span style="color: #800080;">1</span><span style="color: #800000;">&#93;</span>.<span style="color: #008080;">$matches</span><span style="color: #800000;">&#91;</span><span style="color: #800080;">2</span><span style="color: #800000;">&#93;</span>.<span style="color: #ff00ff;">'-'</span>.<span style="color: #008080;">$matches</span><span style="color: #800000;">&#91;</span><span style="color: #800080;">5</span><span style="color: #800000;">&#93;</span>.<span style="color: #008080;">$matches</span><span style="color: #800000;">&#91;</span><span style="color: #800080;">3</span><span style="color: #800000;">&#93;</span>;
<span style="color: #800000;">&#125;</span></pre></div>

<p><span id="more-179"></span><br />
2. 打开主题目录下的<code>single.php</code>文件，查找<code>wp_link_pages</code>并替换为<code>my_wp_link_pages</code>。</p>
<p>3. 后台“设置-永久链接”点击一下“保存修改”按钮，大功告成。</p>
<p>至于 life97 同学说的 <a href="http://www.voidman.com/2008/03/create-static-html-files-for-paged-post.html#comment-3781">.html/xxx 形式的链接访问失效</a>，这个可能和服务器设置有关，具体原因我也不是很清楚，不过可以通过在 .htaccess 文件中添加规则来解决此问题，如：</p>

<div class="wp_syntax"><pre class="apache">&lt;ifmodule mod_rewrite.c&gt;
<span style="color: #00007f;">RewriteEngine</span> <span style="color: #0000ff;">On</span>
<span style="color: #00007f;">RewriteBase</span> /
<span style="color: #00007f;">RewriteRule</span> ^<span style="color: #800000;">&#40;</span><span style="color: #800000;">&#91;</span><span style="color: #ff0000;">0</span><span style="color: #ff0000;">-9</span><span style="color: #800000;">&#93;</span><span style="color: #800000;">&#123;</span><span style="color: #ff0000;">4</span><span style="color: #800000;">&#125;</span><span style="color: #800000;">&#41;</span>/<span style="color: #800000;">&#40;</span><span style="color: #800000;">&#91;</span><span style="color: #ff0000;">0</span><span style="color: #ff0000;">-9</span><span style="color: #800000;">&#93;</span><span style="color: #800000;">&#123;</span><span style="color: #ff0000;">1</span>,<span style="color: #ff0000;">2</span><span style="color: #800000;">&#125;</span><span style="color: #800000;">&#41;</span>/<span style="color: #800000;">&#40;</span><span style="color: #800000;">&#91;</span>^/<span style="color: #800000;">&#93;</span>+<span style="color: #800000;">&#41;</span>\.html/trackback/?$ index.php?year=$<span style="color: #ff0000;">1</span>&amp;monthnum=$<span style="color: #ff0000;">2</span>&amp;name=$<span style="color: #ff0000;">3</span>&amp;tb=<span style="color: #ff0000;">1</span> <span style="color: #800000;">&#91;</span>L<span style="color: #800000;">&#93;</span>
<span style="color: #00007f;">RewriteRule</span> ^<span style="color: #800000;">&#40;</span><span style="color: #800000;">&#91;</span><span style="color: #ff0000;">0</span><span style="color: #ff0000;">-9</span><span style="color: #800000;">&#93;</span><span style="color: #800000;">&#123;</span><span style="color: #ff0000;">4</span><span style="color: #800000;">&#125;</span><span style="color: #800000;">&#41;</span>/<span style="color: #800000;">&#40;</span><span style="color: #800000;">&#91;</span><span style="color: #ff0000;">0</span><span style="color: #ff0000;">-9</span><span style="color: #800000;">&#93;</span><span style="color: #800000;">&#123;</span><span style="color: #ff0000;">1</span>,<span style="color: #ff0000;">2</span><span style="color: #800000;">&#125;</span><span style="color: #800000;">&#41;</span>/<span style="color: #800000;">&#40;</span><span style="color: #800000;">&#91;</span>^/<span style="color: #800000;">&#93;</span>+<span style="color: #800000;">&#41;</span>\.html/feed/<span style="color: #800000;">&#40;</span>feed|rdf|rss|rss2|atom<span style="color: #800000;">&#41;</span>/?$ index.php?year=$<span style="color: #ff0000;">1</span>&amp;monthnum=$<span style="color: #ff0000;">2</span>&amp;name=$<span style="color: #ff0000;">3</span>&amp;feed=$<span style="color: #ff0000;">4</span> <span style="color: #800000;">&#91;</span>L<span style="color: #800000;">&#93;</span>
<span style="color: #00007f;">RewriteRule</span> ^<span style="color: #800000;">&#40;</span><span style="color: #800000;">&#91;</span><span style="color: #ff0000;">0</span><span style="color: #ff0000;">-9</span><span style="color: #800000;">&#93;</span><span style="color: #800000;">&#123;</span><span style="color: #ff0000;">4</span><span style="color: #800000;">&#125;</span><span style="color: #800000;">&#41;</span>/<span style="color: #800000;">&#40;</span><span style="color: #800000;">&#91;</span><span style="color: #ff0000;">0</span><span style="color: #ff0000;">-9</span><span style="color: #800000;">&#93;</span><span style="color: #800000;">&#123;</span><span style="color: #ff0000;">1</span>,<span style="color: #ff0000;">2</span><span style="color: #800000;">&#125;</span><span style="color: #800000;">&#41;</span>/<span style="color: #800000;">&#40;</span><span style="color: #800000;">&#91;</span>^/<span style="color: #800000;">&#93;</span>+<span style="color: #800000;">&#41;</span>\.html/<span style="color: #800000;">&#40;</span>feed|rdf|rss|rss2|atom<span style="color: #800000;">&#41;</span>/?$ index.php?year=$<span style="color: #ff0000;">1</span>&amp;monthnum=$<span style="color: #ff0000;">2</span>&amp;name=$<span style="color: #ff0000;">3</span>&amp;feed=$<span style="color: #ff0000;">4</span> <span style="color: #800000;">&#91;</span>L<span style="color: #800000;">&#93;</span>
&lt;/ifmodule&gt;</pre></div>

<p>注意添加顺序，不要置于 WordPress 生成的规则之后。</p>
<p>下面是几种其它永久链接结构的具体修改代码：</p>
<ul>
<li><a href="http://img.voidman.com/wp/2008/11/year-monthnumday-postname.txt">/%year%/%monthnum%%day%/%postname%.html</a></li>
<li><a href="http://img.voidman.com/wp/2008/11/html-year-monthnum-day-postname.txt">/html/%year%/%monthnum%/%day%/%postname%.html</a></li>
<li><a href="http://img.voidman.com/wp/2008/11/category-year-monthnum-day-post_id.txt">/%category%/%year%/%monthnum%/%day%/%post_id%.html</a></li>
<li><a href="http://img.voidman.com/wp/2008/11/year-monthnumday-post_id.txt">/%year%/%monthnum%%day%/%post_id%.html</a></li>
<li><a href="http://img.voidman.com/wp/2008/11/html-post_id.txt">/html/%post_id%.html</a></li>
<li><a href="http://img.voidman.com/wp/2008/11/html-postname.txt">/html/%postname%.html</a></li>
<li><a href="http://img.voidman.com/wp/2008/11/post-postname.txt">/post/%postname%.html</a></li>
<li><a href="http://img.voidman.com/wp/2008/11/postname.txt">/%postname%.html</a></li>
<li><a href="http://img.voidman.com/wp/2008/11/category-post_id.txt">/%category%-%post_id%.html</a></li>
<li><a href="http://img.voidman.com/wp/2008/11/category-post_id2.txt">/%category%/%post_id%.html</a></li>
<li><a href="http://img.voidman.com/wp/2008/11/category-postname.txt">/%category%/%postname%.html</a></li>
</ul>
<p><strong>UPDATE at 2009-4-1</strong><br />
添加<code>/%year%/%monthnum%%day%/%post_id%.html</code>与<code>/html/%post_id%.html</code>这两种永久链接结构的修改代码</p>
<p><strong>UPDATE at 2009-4-25</strong><br />
添加<code>/%category%-%post_id%.html</code>永久链接结构的修改代码</p>
<p><strong>UPDATE at 2009-5-31</strong><br />
添加<code>/%category%/%postname%.html</code>永久链接结构的修改代码</p>
<p><strong>UPDATE at 2009-9-30</strong><br />
添加<code>/%category%/%year%/%monthnum%/%day%/%post_id%.html</code>永久链接结构的修改代码</p>
<h4>Related Posts</h4><ul class="related_post"><li><a href="http://www.voidman.com/2008/03/create-static-html-files-for-paged-post.html" title="让 Wordpress 分页文章也可以静态化">让 Wordpress 分页文章也可以静态化</a></li><li><a href="http://www.voidman.com/2008/03/trouble-with-static-wordpress.html" title="Wordpress 静态化的烦恼">Wordpress 静态化的烦恼</a></li><li><a href="http://www.voidman.com/2008/03/wordpress-can-coexist-with-gizp-and-cos-html-cache.html" title="让 GZIP 与 cos-html-cache 共存">让 GZIP 与 cos-html-cache 共存</a></li><li><a href="http://www.voidman.com/2009/05/using-wordpress-plugin-api-hack-discuz.html" title="WordPress 的 Hook 机制在 Discuz 二次开发中的应用">WordPress 的 Hook 机制在 Discuz 二次开发中的应用</a></li><li><a href="http://www.voidman.com/2009/04/at-reply-mail-notification-1-release.html" title="At Reply Mail Notification 1.0 Release">At Reply Mail Notification 1.0 Release</a></li><li><a href="http://www.voidman.com/2009/03/lbs-to-wordpress.html" title="LBS 转 WordPress 不完全记录">LBS 转 WordPress 不完全记录</a></li><li><a href="http://www.voidman.com/2009/01/wordpress-is-using-a-bad-way-to-detect-duplicate-comment.html" title="Wordpress 糟糕的重复评论检测方式">Wordpress 糟糕的重复评论检测方式</a></li><li><a href="http://www.voidman.com/2009/01/at-reply-mail-notification-test.html" title="At Reply Mail Notification 测试贴">At Reply Mail Notification 测试贴</a></li><li><a href="http://www.voidman.com/2008/11/automatically-delete-post-revisions.html" title="让 Wordpress 自动删除 Post Revisions">让 Wordpress 自动删除 Post Revisions</a></li><li><a href="http://www.voidman.com/2008/11/google-xml-sitemaps-ignore-the-specified-categories.html" title="让 Google Sitemaps Generator 可以忽略指定的日志分类">让 Google Sitemaps Generator 可以忽略指定的日志分类</a></li></ul><hr /><a href="http://www.voidman.com">Voidman.com</a> | Link: <a href="http://www.voidman.com/2008/11/the-better-solution-for-static-paged-post.html">http://www.voidman.com/2008/11/the-better-solution-for-static-paged-post.html</a><br /><img alt="linezing" width="1" height="1" src="http://img.tongji.linezing.com/288120/tongji.gif" />]]></content:encoded>
			<wfw:commentRss>http://www.voidman.com/2008/11/the-better-solution-for-static-paged-post.html/feed</wfw:commentRss>
		<slash:comments>73</slash:comments>
		</item>
		<item>
		<title>升级到 WordPress 2.6</title>
		<link>http://www.voidman.com/2008/07/upgraded-to-wordpress-v26.html</link>
		<comments>http://www.voidman.com/2008/07/upgraded-to-wordpress-v26.html#comments</comments>
		<pubDate>Wed, 16 Jul 2008 14:34:00 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Blog Related]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.voidman.com/?p=164</guid>
		<description><![CDATA[好久没写博客了，出来冒个泡。最近状态比较低迷，半死不活中…… Related PostsWordPress 的 Hook 机制在 Discuz 二次开发中的应用At Reply Mail Notification 1.0 ReleaseLBS 转 WordPress 不完全记录Wordpress 糟糕的重复评论检测方式At Reply Mail Notification 测试贴让 Wordpress 自动删除 Post Revisions让 Google Sitemaps Generator 可以忽略指定的日志分类Wordpress 分页文章静态化的更优解决方案升级到 WordPress 2.5 RC1WordPress Theme WPCandy RemixVoidman.com &#124; Link: http://www.voidman.com/2008/07/upgraded-to-wordpress-v26.html]]></description>
			<content:encoded><![CDATA[<p>好久没写博客了，出来冒个泡。最近状态比较低迷，半死不活中……</p>
<h4>Related Posts</h4><ul class="related_post"><li><a href="http://www.voidman.com/2009/05/using-wordpress-plugin-api-hack-discuz.html" title="WordPress 的 Hook 机制在 Discuz 二次开发中的应用">WordPress 的 Hook 机制在 Discuz 二次开发中的应用</a></li><li><a href="http://www.voidman.com/2009/04/at-reply-mail-notification-1-release.html" title="At Reply Mail Notification 1.0 Release">At Reply Mail Notification 1.0 Release</a></li><li><a href="http://www.voidman.com/2009/03/lbs-to-wordpress.html" title="LBS 转 WordPress 不完全记录">LBS 转 WordPress 不完全记录</a></li><li><a href="http://www.voidman.com/2009/01/wordpress-is-using-a-bad-way-to-detect-duplicate-comment.html" title="Wordpress 糟糕的重复评论检测方式">Wordpress 糟糕的重复评论检测方式</a></li><li><a href="http://www.voidman.com/2009/01/at-reply-mail-notification-test.html" title="At Reply Mail Notification 测试贴">At Reply Mail Notification 测试贴</a></li><li><a href="http://www.voidman.com/2008/11/automatically-delete-post-revisions.html" title="让 Wordpress 自动删除 Post Revisions">让 Wordpress 自动删除 Post Revisions</a></li><li><a href="http://www.voidman.com/2008/11/google-xml-sitemaps-ignore-the-specified-categories.html" title="让 Google Sitemaps Generator 可以忽略指定的日志分类">让 Google Sitemaps Generator 可以忽略指定的日志分类</a></li><li><a href="http://www.voidman.com/2008/11/the-better-solution-for-static-paged-post.html" title="Wordpress 分页文章静态化的更优解决方案">Wordpress 分页文章静态化的更优解决方案</a></li><li><a href="http://www.voidman.com/2008/03/upgraded-to-wordpress-25-rc1.html" title="升级到 WordPress 2.5 RC1">升级到 WordPress 2.5 RC1</a></li><li><a href="http://www.voidman.com/2008/03/wordpress-theme-wpcandy-remix.html" title="WordPress Theme WPCandy Remix">WordPress Theme WPCandy Remix</a></li></ul><hr /><a href="http://www.voidman.com">Voidman.com</a> | Link: <a href="http://www.voidman.com/2008/07/upgraded-to-wordpress-v26.html">http://www.voidman.com/2008/07/upgraded-to-wordpress-v26.html</a><br /><img alt="linezing" width="1" height="1" src="http://img.tongji.linezing.com/288120/tongji.gif" />]]></content:encoded>
			<wfw:commentRss>http://www.voidman.com/2008/07/upgraded-to-wordpress-v26.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>升级到 WordPress 2.5 RC1</title>
		<link>http://www.voidman.com/2008/03/upgraded-to-wordpress-25-rc1.html</link>
		<comments>http://www.voidman.com/2008/03/upgraded-to-wordpress-25-rc1.html#comments</comments>
		<pubDate>Wed, 19 Mar 2008 16:34:47 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Blog Related]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.voidman.com/?p=151</guid>
		<description><![CDATA[忍不住登上服务器将 WordPress 升级到 2.5 RC1，还算顺利。感觉后台速度有所提高，不知道真的是后台速度提升了还是网速提升了（这两天 ping 延时破天荒地小于 300 ms）。 后台色调较之前明快了许多，不过我更喜欢经典色调，看上比较舒服；FF、Safari 下可以看到漂亮的圆角按钮，IE、Opera 便无福消受了。 使用的插件大部分工作正常，不过由于 WordPress 2.5 修改了 COOKIE 设置，用 AUTH_COOKIE 替代了原先的 USER_COOKIE 和 PASS_COOKIE，这使得 cos-html-cache 无法正常工作，需要做些简单的修改。貌似 RSS 全文输出不受 more 标签影响了，看来 Full Text Feed 插件该退役了。 发现 WordPress 2.5 去掉了 gzip 压缩，不知道出于什么原因。WordPress 2.5 还改进更改了内置的缓存机制，替代了之前基于文件的缓存机制而完全基于内存操作。只不过这个新的缓存机制并不能有效降低数据库负载，如同鸡肋一般。另外，在循环中执行查询这个严重影响效率的该拍砖头扔臭鸡蛋的环节仍旧没有得到有效改善。 Related PostsWordPress 的 Hook 机制在 Discuz 二次开发中的应用At Reply Mail Notification 1.0 ReleaseLBS 转 WordPress [...]]]></description>
			<content:encoded><![CDATA[<p>忍不住登上服务器将 WordPress 升级到 2.5 RC1，还算顺利。感觉后台速度有所提高，不知道真的是后台速度提升了还是网速提升了（这两天 ping 延时破天荒地小于 300 ms）。</p>
<p>后台色调较之前明快了许多，不过我更喜欢经典色调，看上比较舒服；FF、Safari 下可以看到漂亮的圆角按钮，IE、Opera 便无福消受了。</p>
<p>使用的插件大部分工作正常，不过由于 WordPress 2.5 修改了 COOKIE 设置，用 AUTH_COOKIE 替代了原先的 USER_COOKIE 和 PASS_COOKIE，这使得 cos-html-cache 无法正常工作，需要做些简单的修改。貌似 RSS 全文输出不受 more 标签影响了，看来 Full Text Feed 插件该退役了。</p>
<p>发现 WordPress 2.5 去掉了 gzip 压缩，不知道出于什么原因。WordPress 2.5 还<del datetime="2008-03-23T14:18:48+00:00">改进</del><ins datetime="2008-03-23T14:18:48+00:00">更改</ins>了内置的缓存机制，替代了之前基于文件的缓存机制而完全基于内存操作。只不过这个新的缓存机制并不能有效降低数据库负载，如同鸡肋一般。另外，在循环中执行查询这个严重影响效率的该拍砖头扔臭鸡蛋的环节仍旧没有得到有效改善。</p>
<h4>Related Posts</h4><ul class="related_post"><li><a href="http://www.voidman.com/2009/05/using-wordpress-plugin-api-hack-discuz.html" title="WordPress 的 Hook 机制在 Discuz 二次开发中的应用">WordPress 的 Hook 机制在 Discuz 二次开发中的应用</a></li><li><a href="http://www.voidman.com/2009/04/at-reply-mail-notification-1-release.html" title="At Reply Mail Notification 1.0 Release">At Reply Mail Notification 1.0 Release</a></li><li><a href="http://www.voidman.com/2009/03/lbs-to-wordpress.html" title="LBS 转 WordPress 不完全记录">LBS 转 WordPress 不完全记录</a></li><li><a href="http://www.voidman.com/2009/01/wordpress-is-using-a-bad-way-to-detect-duplicate-comment.html" title="Wordpress 糟糕的重复评论检测方式">Wordpress 糟糕的重复评论检测方式</a></li><li><a href="http://www.voidman.com/2009/01/at-reply-mail-notification-test.html" title="At Reply Mail Notification 测试贴">At Reply Mail Notification 测试贴</a></li><li><a href="http://www.voidman.com/2008/11/automatically-delete-post-revisions.html" title="让 Wordpress 自动删除 Post Revisions">让 Wordpress 自动删除 Post Revisions</a></li><li><a href="http://www.voidman.com/2008/11/google-xml-sitemaps-ignore-the-specified-categories.html" title="让 Google Sitemaps Generator 可以忽略指定的日志分类">让 Google Sitemaps Generator 可以忽略指定的日志分类</a></li><li><a href="http://www.voidman.com/2008/11/the-better-solution-for-static-paged-post.html" title="Wordpress 分页文章静态化的更优解决方案">Wordpress 分页文章静态化的更优解决方案</a></li><li><a href="http://www.voidman.com/2008/07/upgraded-to-wordpress-v26.html" title="升级到 WordPress 2.6">升级到 WordPress 2.6</a></li><li><a href="http://www.voidman.com/2008/03/wordpress-theme-wpcandy-remix.html" title="WordPress Theme WPCandy Remix">WordPress Theme WPCandy Remix</a></li></ul><hr /><a href="http://www.voidman.com">Voidman.com</a> | Link: <a href="http://www.voidman.com/2008/03/upgraded-to-wordpress-25-rc1.html">http://www.voidman.com/2008/03/upgraded-to-wordpress-25-rc1.html</a><br /><img alt="linezing" width="1" height="1" src="http://img.tongji.linezing.com/288120/tongji.gif" />]]></content:encoded>
			<wfw:commentRss>http://www.voidman.com/2008/03/upgraded-to-wordpress-25-rc1.html/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
