<?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>Bolo的博客 &#187; WordPress</title>
	<atom:link href="http://blog.imbolo.com/tag/wordpress/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.imbolo.com</link>
	<description>一个设计爱好者杂七杂八的博客</description>
	<lastBuildDate>Wed, 23 Nov 2011 16:19:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>WordPress 3.2 新亮点</title>
		<link>http://blog.imbolo.com/whats-coming-in-wordpress-3-2/</link>
		<comments>http://blog.imbolo.com/whats-coming-in-wordpress-3-2/#comments</comments>
		<pubDate>Thu, 05 May 2011 17:12:25 +0000</pubDate>
		<dc:creator>bolo</dc:creator>
				<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://blog.imbolo.com/?p=1998</guid>
		<description><![CDATA[WordPress 即将更新到 3.2，和 3.1 的理念一样，WordPress 3.2 将继续在用户体验上下功夫。WordPress 3.2 将会有以下更新。]]></description>
			<content:encoded><![CDATA[<p>WordPress 即将更新到 3.2，和 3.1 的理念一样，WordPress 3.2 将继续在用户体验上下功夫。WordPress 3.2 将会有以下更新。</p>
<h3>新的后台样式</h3>
<p><img src="http://i1001.photobucket.com/albums/af131/bolo1988/dashboard.gif" alt="WordPress 3.2 后台样式" /></p>
<p>WordPress 3.2 的后台样式将更加清爽、时尚。</p>
<p><span id="more-1998"></span></p>
<h3>新的默认主题</h3>
<p><img src="http://i1001.photobucket.com/albums/af131/bolo1988/2011v2.gif" alt="WordPress 3.2 默认主题 Twenty Eleven" /></p>
<p>WordPress 3.2 的默认主题为新设计的 Twenty Eleven 主题，该主题布局和 Twenty Ten 差不多，到在后台可以选择黑/白两种配色，并且有几种默认的分栏布局可以选择。</p>
<h3>改进升级程序</h3>
<p>以前 WordPress 升级的时候会下载整个压缩包，使很多国内主机用户在升级 WordPress 经常遭遇服务器超时。而改良后的升级程序只会更新相对于当前版本有所改动的文件，升级速度大大提高。</p>
<h3>广阔的写作空间</h3>
<p><img src="http://i1001.photobucket.com/albums/af131/bolo1988/distractionfree.gif" alt="WordPress 3.2 全屏写作" /></p>
<p>WordPress 的文章编辑器总是显得很狭隘，非常不利于调整内容排版，WordPress 3.2 的文章编辑器将可以扩大至全屏！尽情写作吧。</p>
<h3>提升运行效率</h3>
<p>WordPress 3.2 会去掉核心代码里一些罗哩罗嗦的地方，以提高整体效率。在为是否用 WordPress 建站的你们，以后可以放下这块心头石了。</p>
<h3>新的 PHP 和 MySQL 环境需求</h3>
<p>WordPress 3.2 要求服务器最低要有 PHP 5.2.4 和 MySQL5 的环境，在准备升级 WordPress 3.2 前，请先用探针查看自己服务器的配置，实在不行就顺便换个更好的服务器吧。</p>
<p>BTW，据说 WordPress 3.2 将在 2011 年 6 月 30 日发布，期待吧。</p>
<p  class="related_post_title">Related Posts</p><ul class="related_post"><li><a href="http://blog.imbolo.com/wordpress-3-2-the-plan-faster-lighter/" title="WordPress 3.2 将着重提高效率和程序轻量化">WordPress 3.2 将着重提高效率和程序轻量化</a></li><li><a href="http://blog.imbolo.com/wp-plugin-author-list-plus/" title="适合多人博客的作者列表插件：Author-List-Plus">适合多人博客的作者列表插件：Author-List-Plus</a></li><li><a href="http://blog.imbolo.com/improve-wordpress-navigation-menu-output/" title="为 WordPress 3.0 自定义菜单添加描述">为 WordPress 3.0 自定义菜单添加描述</a></li><li><a href="http://blog.imbolo.com/customizing-the-new-wordpress-3-0-custom-menus-adding-different-icons-to-each-link/" title="为 WordPress 3.0 的自定义菜单链接添加栏目图标">为 WordPress 3.0 的自定义菜单链接添加栏目图标</a></li><li><a href="http://blog.imbolo.com/wordpress-insert-a-advertisement-at-the-more-tag/" title="WordPress 在 more 截断处插入广告">WordPress 在 more 截断处插入广告</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://blog.imbolo.com/whats-coming-in-wordpress-3-2/feed/</wfw:commentRss>
		<slash:comments>30</slash:comments>
		</item>
		<item>
		<title>WordPress 3.2 将着重提高效率和程序轻量化</title>
		<link>http://blog.imbolo.com/wordpress-3-2-the-plan-faster-lighter/</link>
		<comments>http://blog.imbolo.com/wordpress-3-2-the-plan-faster-lighter/#comments</comments>
		<pubDate>Sat, 19 Mar 2011 19:41:31 +0000</pubDate>
		<dc:creator>bolo</dc:creator>
				<category><![CDATA[Develop]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://blog.imbolo.com/?p=1994</guid>
		<description><![CDATA[据可靠消息说 WordPress 核心开发人员已经着手 WordPress 3.2 的开发，以保证 3.2 版不会像 3.1 版一样，在正式版发布前让广大用户等得脖子都长了。虽然 WordPress 3.1 的某些更新的确让我们感觉耳目一新，但这等待的时间也有点太 TM 长了吧？]]></description>
			<content:encoded><![CDATA[<p>据可靠消息说 WordPress 核心开发人员已经着手 WordPress 3.2 的开发，以保证 3.2 版不会像 3.1 版一样，在正式版发布前让广大用户等得脖子都长了。虽然 WordPress 3.1 的某些更新的确让我们感觉耳目一新，但这等待的时间也有点太 TM 长了吧？</p>
<p>WordPress 3.2 将注重于程序效率和代码轻量化的改进。目前所知的重要更新主要有下面这几点：</p>
<p><span id="more-1994"></span></p>
<ol>
<li>将放弃对过时技术的支持。包括服务器 PHP 版本必须为 5.2 以上，MySQL 版本必须为 5 以上，并且在后台界面逐渐放弃对 IE6 的兼容（好事！）。</li>
<li>改进 List table API，增加灵活性，方便二次开发。</li>
<li>List Table XHR loading，暂时不知道具体是什么货，估计是优化用户体验。</li>
<li>改进博客写作体验，依照个人估计， WordPress 官方不会一下子放弃 TinyMCE 界面，但是据说以后会慢慢向 <a href="http://www.quietwrite.com/" rel="nofollow" target="_blank">http://www.quietwrite.com/</a> 看齐。</li>
<li>改进升级程序。据说以后在升级 WordPress 的时候，如果你对程序文件进行了改动的话，这些文件将不会被覆盖，仅更新没有修改过的文件。不过说句实话，改程序文件是非常不安全的，如果你找我进行 WordPress 二次开发的话，我可以保证不修改 WordPress 源文件。</li>
<li>程序速度优化，WordPress 可能会引入某种缓存机制来提高 WordPress 的运行速度。插一句，我至今不明白为什么 WordPress 一直在 config 里留着 Cache 的选项，但缓存程序却至今未在源码中出现。</li>
</ol>
<p  class="related_post_title">Related Posts</p><ul class="related_post"><li><a href="http://blog.imbolo.com/whats-coming-in-wordpress-3-2/" title="WordPress 3.2 新亮点">WordPress 3.2 新亮点</a></li><li><a href="http://blog.imbolo.com/wp-plugin-author-list-plus/" title="适合多人博客的作者列表插件：Author-List-Plus">适合多人博客的作者列表插件：Author-List-Plus</a></li><li><a href="http://blog.imbolo.com/improve-wordpress-navigation-menu-output/" title="为 WordPress 3.0 自定义菜单添加描述">为 WordPress 3.0 自定义菜单添加描述</a></li><li><a href="http://blog.imbolo.com/customizing-the-new-wordpress-3-0-custom-menus-adding-different-icons-to-each-link/" title="为 WordPress 3.0 的自定义菜单链接添加栏目图标">为 WordPress 3.0 的自定义菜单链接添加栏目图标</a></li><li><a href="http://blog.imbolo.com/wordpress-insert-a-advertisement-at-the-more-tag/" title="WordPress 在 more 截断处插入广告">WordPress 在 more 截断处插入广告</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://blog.imbolo.com/wordpress-3-2-the-plan-faster-lighter/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>适合多人博客的作者列表插件：Author-List-Plus</title>
		<link>http://blog.imbolo.com/wp-plugin-author-list-plus/</link>
		<comments>http://blog.imbolo.com/wp-plugin-author-list-plus/#comments</comments>
		<pubDate>Fri, 10 Sep 2010 12:13:54 +0000</pubDate>
		<dc:creator>bolo</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Plugins]]></category>

		<guid isPermaLink="false">http://blog.imbolo.com/?p=1957</guid>
		<description><![CDATA[Author-List-Plus 是 CantonBolo 为 WPJAM 应用商城做的第一个收费 WordPress 插件。能自动显示博客里所有作者的用户资料并统计每个作者的文章数，非常适合多人博客。]]></description>
			<content:encoded><![CDATA[<p>Author-List-Plus 是 CantonBolo 为 <a href="http://wpjam.net/?ref=CantonBolo">WPJAM 应用商城</a> 做的第一个收费 WordPress 插件。能自动显示博客里所有作者的用户资料并统计每个作者的文章数，非常适合多人博客。</p>
<p><img src="http://i1001.photobucket.com/albums/af131/bolo1988/65e9cca0.png" alt="作者列表预览" /></p>
<p>作为一个多人博客，如何才能让你的访客更多地了解博客的撰稿人们呢？建立一个完善的作者列表是一个效果良好的做法。而 Author-List-Plus 插件则可以满足大部分多人博客的需求，除了 WordPress 默认支持的个人资料以外，Author-List-Plus 还可以让每个作者都设置自己的所在地、SNS、微博等资料，博客管理员可以设置在作者列表里显示哪些资料，而更为强大的是，博主无需修改主题模板，Author-List-Plus 可以自动把作者列表添加到特定的页面里，使用非常简单！</p>
<p><span id="more-1957"></span><br />
<img src="http://i1001.photobucket.com/albums/af131/bolo1988/6322118f.png" alt="详细的后台选项" /></p>
<p>当然，如果你想作者列表更加美观的话，你可以为作者列表写一个样式，Author-List-Plus 默认生成的 HTML 结构以足够让你写出非常漂亮的样式！</p>
<h2>使用方法</h2>
<ol>
<li>上传并激活插件后，每个作者都可以在自己的 Profile (档案) 页面添加更多的自定义资料</li>
<li>博客管理员可以在 Author List Plus Options 页面定制作者列表显示的内容</li>
</ol>
<p>Author-List-Plus 只售 <strong>￥ 9.98</strong> ，需要的童鞋可以到 <a href="http://wpjam.net/item/author-list-plus/?ref=CantonBolo">WPJAM 应用商城</a> 购买。</p>
<p  class="related_post_title">Related Posts</p><ul class="related_post"><li><a href="http://blog.imbolo.com/wordpress-plugin-ibegin-share-mod/" title="WordPress 分享插件：iBegin Share (mod)">WordPress 分享插件：iBegin Share (mod)</a></li><li><a href="http://blog.imbolo.com/diy-a-plugin/" title="做一个自己的插件">做一个自己的插件</a></li><li><a href="http://blog.imbolo.com/wordpress-plugin-admin-post-navigation/" title="插件推荐：Admin Post Navigation">插件推荐：Admin Post Navigation</a></li><li><a href="http://blog.imbolo.com/overlay4wp/" title="WordPress相册插件：Overlay4WP">WordPress相册插件：Overlay4WP</a></li><li><a href="http://blog.imbolo.com/whats-coming-in-wordpress-3-2/" title="WordPress 3.2 新亮点">WordPress 3.2 新亮点</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://blog.imbolo.com/wp-plugin-author-list-plus/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
		<item>
		<title>为 WordPress 3.0 自定义菜单添加描述</title>
		<link>http://blog.imbolo.com/improve-wordpress-navigation-menu-output/</link>
		<comments>http://blog.imbolo.com/improve-wordpress-navigation-menu-output/#comments</comments>
		<pubDate>Tue, 20 Jul 2010 06:04:42 +0000</pubDate>
		<dc:creator>bolo</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Skill]]></category>
		<category><![CDATA[Theme]]></category>

		<guid isPermaLink="false">http://blog.imbolo.com/?p=1914</guid>
		<description><![CDATA[WordPress 3.0 增加了一个强大的自定义菜单功能，但美中不足是要实现题图这样包含描述的菜单时，单靠目前 WordPress 的功能还无法实现。本文将教你改变 WordPress 默认的菜单输出，打造更加个性的菜单。]]></description>
			<content:encoded><![CDATA[<p><img src="http://i1001.photobucket.com/albums/af131/bolo1988/1-3.png" alt="WordPress 带描述的菜单" /></p>
<p>WordPress 3.0 增加了一个强大的自定义菜单功能，但美中不足是要实现题图这样包含描述的菜单时，单靠目前 WordPress 的功能还无法实现。本文将教你改变 WordPress 默认的菜单输出，打造更加个性的菜单。</p>
<p>也许你已经知道，当后台出现 <strong>Appearance > Menus</strong> 这个菜单项的时候，就标明你使用的主题支持 WordPress 3.0 自定义菜单。只需要用 <a href="http://codex.wordpress.org/Function_Reference/wp_nav_menu">wp_nav_menu()</a> 函数进行调用即可。但问题是 WordPress 输出的菜单 HTML 结构如下：<span id="more-1914"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="html4strick" style="font-family:monospace;">&lt;ul id=&quot;menu-main&quot;&gt;
    &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Home&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;#&quot;&gt;About&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Contact&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Blog&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</pre></td></tr></table></div>

<p>但我们需要的是像下面这种结构的菜单：</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="html4strick" style="font-family:monospace;">&lt;ul id=&quot;menu-main&quot;&gt;
     &lt;li&gt;&lt;a href=&quot;#&quot;&gt;&lt;strong&gt;Home&lt;/strong&gt;&lt;span&gt;Description&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
     &lt;li&gt;&lt;a href=&quot;#&quot;&gt;&lt;strong&gt;About&lt;/strong&gt;&lt;span&gt;Description&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
     &lt;li&gt;&lt;a href=&quot;#&quot;&gt;&lt;strong&gt;Contact&lt;/strong&gt;&lt;span&gt;Description&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
     &lt;li&gt;&lt;a href=&quot;#&quot;&gt;&lt;strong&gt;Blog&lt;/strong&gt;&lt;span&gt;Description&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</pre></td></tr></table></div>

<p>通过对比，很明显 WordPress 默认输出的菜单结构并不能满足我们的要求。我们需要做的是先为每个菜单项写上 description，然后添加一个 filter 对 WordPress 输出的菜单进行整理。</p>
<p>在 <strong>Appearance > Menus</strong> 页面，菜单项的 description 输入框默认是隐藏的，我们可以在页顶的 <strong>Screen Options</strong> 里把 <strong>Description</strong> 勾上。<br />
<img src="http://i1001.photobucket.com/albums/af131/bolo1988/2-3.png" alt="显示菜单项描述输入框" /><br />
然后我们就开始为菜单项加上描述吧！<br />
<img src="http://i1001.photobucket.com/albums/af131/bolo1988/3-3.png" alt="填写菜单项描述" /><br />
在默认情况下，WordPress 已经自动为 Page 菜单项写上了长长的描述，在这里我们可以把这些描述改为自己喜欢的内容。</p>
<p>接下来我们要写一个 filter 用来整理 WordPress 输出的菜单代码。<a href="http://codex.wordpress.org/Function_Reference/wp_nav_menu">wp_nav_menu()</a> 函数有一个 <strong>walker</strong> 参数，我们通过这个参数来调用 filter。下面是 filter 的代码：</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
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> description_walker <span style="color: #000000; font-weight: bold;">extends</span> Walker_Nav_Menu
<span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">function</span> start_el<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span><span style="color: #000088;">$output</span><span style="color: #339933;">,</span> <span style="color: #000088;">$item</span><span style="color: #339933;">,</span> <span style="color: #000088;">$depth</span><span style="color: #339933;">,</span> <span style="color: #000088;">$args</span><span style="color: #009900;">&#41;</span>
      <span style="color: #009900;">&#123;</span>
           <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$wp_query</span><span style="color: #339933;">;</span>
           <span style="color: #000088;">$indent</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$depth</span> <span style="color: #009900;">&#41;</span> ? <span style="color: #990000;">str_repeat</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$depth</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
&nbsp;
           <span style="color: #000088;">$class_names</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$value</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
&nbsp;
           <span style="color: #000088;">$classes</span> <span style="color: #339933;">=</span> <span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">classes</span> <span style="color: #009900;">&#41;</span> ? <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">classes</span><span style="color: #339933;">;</span>
&nbsp;
           <span style="color: #000088;">$class_names</span> <span style="color: #339933;">=</span> <span style="color: #990000;">join</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">' '</span><span style="color: #339933;">,</span> apply_filters<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'nav_menu_css_class'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array_filter</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$classes</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$item</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
           <span style="color: #000088;">$class_names</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">' class=&quot;'</span><span style="color: #339933;">.</span> esc_attr<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$class_names</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot;'</span><span style="color: #339933;">;</span>
&nbsp;
           <span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$indent</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;li id=&quot;menu-item-'</span><span style="color: #339933;">.</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$value</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$class_names</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'&gt;'</span><span style="color: #339933;">;</span>
&nbsp;
           <span style="color: #000088;">$attributes</span>  <span style="color: #339933;">=</span> <span style="color: #339933;">!</span> <span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">attr_title</span> <span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">' title=&quot;'</span>  <span style="color: #339933;">.</span> esc_attr<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">attr_title</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;'</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
           <span style="color: #000088;">$attributes</span> <span style="color: #339933;">.=</span> <span style="color: #339933;">!</span> <span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">target</span> <span style="color: #009900;">&#41;</span>     ? <span style="color: #0000ff;">' target=&quot;'</span> <span style="color: #339933;">.</span> esc_attr<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">target</span>     <span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;'</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
           <span style="color: #000088;">$attributes</span> <span style="color: #339933;">.=</span> <span style="color: #339933;">!</span> <span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">xfn</span> <span style="color: #009900;">&#41;</span>        ? <span style="color: #0000ff;">' rel=&quot;'</span>    <span style="color: #339933;">.</span> esc_attr<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">xfn</span>        <span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;'</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
           <span style="color: #000088;">$attributes</span> <span style="color: #339933;">.=</span> <span style="color: #339933;">!</span> <span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">url</span> <span style="color: #009900;">&#41;</span>        ? <span style="color: #0000ff;">' href=&quot;'</span>   <span style="color: #339933;">.</span> esc_attr<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">url</span>        <span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;'</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
&nbsp;
           <span style="color: #000088;">$prepend</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;strong&gt;'</span><span style="color: #339933;">;</span>
           <span style="color: #000088;">$append</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;/strong&gt;'</span><span style="color: #339933;">;</span>
           <span style="color: #000088;">$description</span>  <span style="color: #339933;">=</span> <span style="color: #339933;">!</span> <span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">description</span> <span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">'&lt;span&gt;'</span><span style="color: #339933;">.</span>esc_attr<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">description</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/span&gt;'</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
&nbsp;
           <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$depth</span> <span style="color: #339933;">!=</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
           <span style="color: #009900;">&#123;</span>
                     <span style="color: #000088;">$description</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$append</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$prepend</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
           <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #000088;">$item_output</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$args</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">before</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$item_output</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;a '</span><span style="color: #339933;">.</span> <span style="color: #000088;">$attributes</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'&gt;'</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$item_output</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$args</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">link_before</span> <span style="color: #339933;">.</span><span style="color: #000088;">$prepend</span><span style="color: #339933;">.</span>apply_filters<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'the_title'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">title</span><span style="color: #339933;">,</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #000088;">$append</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$item_output</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$description</span><span style="color: #339933;">.</span><span style="color: #000088;">$args</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">link_after</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$item_output</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;/a&gt;'</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$item_output</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$args</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">after</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span> apply_filters<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'walker_nav_menu_start_el'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$item_output</span><span style="color: #339933;">,</span> <span style="color: #000088;">$item</span><span style="color: #339933;">,</span> <span style="color: #000088;">$depth</span><span style="color: #339933;">,</span> <span style="color: #000088;">$args</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: #339933;">&lt;/</span>li<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>这个 filter 只是在 WordPress 默认的 walker 脚本的基础上修改了一些内容（原代码在 wp-includes/nav-menu-template.php），并且只为顶级菜单项添加描述。</p>
<p>最后一步，我们只需在调用菜单的时候告诉 WordPress：“调用这个菜单的时候使用我自己的 walker 脚本”，WordPress 就会自动生成你所需要的结构的菜单了。在调用菜单是，我们这样写：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">wp_nav_menu<span style="color: #009900;">&#40;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
	<span style="color: #0000ff;">'container'</span> <span style="color: #339933;">=&gt;</span>false<span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'menu_class'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'nav'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'echo'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'before'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'after'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'link_before'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'link_after'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'depth'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'walker'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">new</span> description_walker<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>要令菜单更好看的话，我们只需要编写自己喜欢的 CSS 样式即可。</p>
<p  class="related_post_title">Related Posts</p><ul class="related_post"><li><a href="http://blog.imbolo.com/customizing-the-new-wordpress-3-0-custom-menus-adding-different-icons-to-each-link/" title="为 WordPress 3.0 的自定义菜单链接添加栏目图标">为 WordPress 3.0 的自定义菜单链接添加栏目图标</a></li><li><a href="http://blog.imbolo.com/inpad/" title="主题发布：Inpad">主题发布：Inpad</a></li><li><a href="http://blog.imbolo.com/custom-gravatar/" title="自定义默认Gravatar头像">自定义默认Gravatar头像</a></li><li><a href="http://blog.imbolo.com/show-the-date-of-each-post/" title="显示每篇文章的日期">显示每篇文章的日期</a></li><li><a href="http://blog.imbolo.com/ajax-posting-comments/" title="为主题添加AJAX提交评论功能">为主题添加AJAX提交评论功能</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://blog.imbolo.com/improve-wordpress-navigation-menu-output/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>为 WordPress 3.0 的自定义菜单链接添加栏目图标</title>
		<link>http://blog.imbolo.com/customizing-the-new-wordpress-3-0-custom-menus-adding-different-icons-to-each-link/</link>
		<comments>http://blog.imbolo.com/customizing-the-new-wordpress-3-0-custom-menus-adding-different-icons-to-each-link/#comments</comments>
		<pubDate>Tue, 25 May 2010 15:18:57 +0000</pubDate>
		<dc:creator>bolo</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Theme]]></category>

		<guid isPermaLink="false">http://blog.imbolo.com/?p=1854</guid>
		<description><![CDATA[WordPress 3.0 为了增强 CMS 功能，加入了自定义菜单的功能，除了定义菜单项目外，还可以菜单定义各个项目的 CSS Class。我们可以利用这个功能来为菜单项目添加一个个性图标。]]></description>
			<content:encoded><![CDATA[<p><img src="http://i1001.photobucket.com/albums/af131/bolo1988/custompagemenuitemicon.png" alt="WordPress 3.0 自定义菜单栏目图标" /></p>
<p>WordPress 3.0 为了增强 CMS 功能，加入了自定义菜单的功能，除了定义菜单项目外，还可以菜单定义各个项目的 CSS Class。我们可以利用这个功能来为菜单项目添加一个个性图标。</p>
<p>在 WordPress 3.0 的 Appearance（外观）-> Menus（菜单）面板里我们可以看到自定义菜单的设置，首先点击“Creat Menu”，再在左栏勾选需要的菜单项目后点击“Add to Menu”可以把勾选的项目添加到刚才建立的自定义菜单里。这是展开菜单项可以看到相关项目的参数。<span id="more-1854"></span></p>
<p><img src="http://i1001.photobucket.com/albums/af131/bolo1988/Captura-de-pantalla-2010-05-24-a-la.png" alt="默认自定义菜单项目参数" /></p>
<p>默认情况下能修改的参数很少，这时点击屏幕左上角的“Screen Options（屏幕参数）”，把“Show advanced menu properties（显示高级菜单属性）”里的项目全部勾选，我们就可以看到更多的参数。以本文题图为例，为各个项目分别加上 Home、Advertise、Contact、Archives 和 About 的 CSS Class，这样在前台调用菜单时，这些项目将拥有一个自定义的 CSS Class，接下来我们可以通过 CSS 为这些项目加上图标。</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
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#header</span> ul<span style="color: #6666ff;">.navigation</span> li a<span style="color: #6666ff;">.home</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">&quot;images/home.png&quot;</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">no-repeat</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">1px</span> <span style="color: #993333;">transparent</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#header</span> ul<span style="color: #6666ff;">.navigation</span> li a<span style="color: #6666ff;">.about</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">&quot;images/about.png&quot;</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">no-repeat</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">0px</span> <span style="color: #993333;">transparent</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#header</span> ul<span style="color: #6666ff;">.navigation</span> li a<span style="color: #6666ff;">.advertise</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">&quot;images/advertise.png&quot;</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">no-repeat</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">0px</span> <span style="color: #993333;">transparent</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#header</span> ul<span style="color: #6666ff;">.navigation</span> li a<span style="color: #6666ff;">.archive</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">&quot;images/archive.png&quot;</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">no-repeat</span> <span style="color: #933;">1px</span> <span style="color: #933;">2px</span> <span style="color: #993333;">transparent</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#header</span> ul<span style="color: #6666ff;">.navigation</span> li a<span style="color: #6666ff;">.contact</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">&quot;images/contact.png&quot;</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">no-repeat</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">3px</span> <span style="color: #993333;">transparent</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p>在 WordPress 3.0 之前的版本里，我们可以通过 JavaScript 等方法为菜单项目加上图标。原理是获取菜单项的 title 值，再为它加上一个和 title 值相同的 Class，在 jQuery 里可以这样写：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; 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: #3366CC;">'ul.navigation li a'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #003366; 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: #000066; font-weight: bold;">return</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'title'</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: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p  class="related_post_title">Related Posts</p><ul class="related_post"><li><a href="http://blog.imbolo.com/improve-wordpress-navigation-menu-output/" title="为 WordPress 3.0 自定义菜单添加描述">为 WordPress 3.0 自定义菜单添加描述</a></li><li><a href="http://blog.imbolo.com/inpad/" title="主题发布：Inpad">主题发布：Inpad</a></li><li><a href="http://blog.imbolo.com/custom-gravatar/" title="自定义默认Gravatar头像">自定义默认Gravatar头像</a></li><li><a href="http://blog.imbolo.com/show-the-date-of-each-post/" title="显示每篇文章的日期">显示每篇文章的日期</a></li><li><a href="http://blog.imbolo.com/ajax-posting-comments/" title="为主题添加AJAX提交评论功能">为主题添加AJAX提交评论功能</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://blog.imbolo.com/customizing-the-new-wordpress-3-0-custom-menus-adding-different-icons-to-each-link/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>WordPress 在 more 截断处插入广告</title>
		<link>http://blog.imbolo.com/wordpress-insert-a-advertisement-at-the-more-tag/</link>
		<comments>http://blog.imbolo.com/wordpress-insert-a-advertisement-at-the-more-tag/#comments</comments>
		<pubDate>Thu, 20 May 2010 05:01:48 +0000</pubDate>
		<dc:creator>bolo</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Advertisment]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://blog.imbolo.com/?p=1847</guid>
		<description><![CDATA[在文章内插入的广告具有相当高的点击率。在 WordPress 里，我发现很多人利用 JavaScript 把广告插入到 more 截断标签处，作为内文广告。昨晚我也在内文里放了 Google Adsense，但我是用 WordPress 自带的 add_filter 函数实现的。]]></description>
			<content:encoded><![CDATA[<p>在文章内插入的广告具有相当高的点击率。在 WordPress 里，我发现很多人利用 JavaScript 把广告插入到 more 截断标签处，作为内文广告。昨晚我也在内文里放了 Google Adsense，但我是用 WordPress 自带的 add_filter 函数实现的。</p>
<p>打开主题的 function.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
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
 * The filter to insert the ads
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> bl_insert_ad_code_filter<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$content</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$id</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// 只在文章页面显示</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span>is_single<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$content</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// 首先插入广告代码</span>
	<span style="color: #000088;">$html</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;div class=&quot;single_ads&quot;&gt;你的广告代码&lt;/div&gt;'</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// more 标签在 WordPress 2.3 前是一个 a 标签，2.3 后是一个 span 标签</span>
		<span style="color: #666666; font-style: italic;">// 保证兼容性</span>
		<span style="color: #b1b100;">return</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;#\《(a|span) id＼=<span style="color: #000099; font-weight: bold;">\&quot;</span>more-<span style="color: #006699; font-weight: bold;">$id</span><span style="color: #000099; font-weight: bold;">\&quot;</span>\》\《/<span style="color: #000099; font-weight: bold;">\\</span>1\》#&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$html</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$0</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</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: #666666; font-style: italic;">//因为 wp-syntax 插件的问题，请把上一句代码中的书名号替换成“&lt; ”和“&gt;”，“＼”换成“\”</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$content</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'the_content'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'bl_insert_ad_code_filter'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">50</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>利用这个 filter 我们还可以在文章任意的地方插入广告，或者添加其他的应用，大家可以尽情发挥创意。<span id="more-1847"></span></p>
<p  class="related_post_title">Related Posts</p><ul class="related_post"><li><a href="http://blog.imbolo.com/whats-coming-in-wordpress-3-2/" title="WordPress 3.2 新亮点">WordPress 3.2 新亮点</a></li><li><a href="http://blog.imbolo.com/wordpress-3-2-the-plan-faster-lighter/" title="WordPress 3.2 将着重提高效率和程序轻量化">WordPress 3.2 将着重提高效率和程序轻量化</a></li><li><a href="http://blog.imbolo.com/wp-plugin-author-list-plus/" title="适合多人博客的作者列表插件：Author-List-Plus">适合多人博客的作者列表插件：Author-List-Plus</a></li><li><a href="http://blog.imbolo.com/improve-wordpress-navigation-menu-output/" title="为 WordPress 3.0 自定义菜单添加描述">为 WordPress 3.0 自定义菜单添加描述</a></li><li><a href="http://blog.imbolo.com/customizing-the-new-wordpress-3-0-custom-menus-adding-different-icons-to-each-link/" title="为 WordPress 3.0 的自定义菜单链接添加栏目图标">为 WordPress 3.0 的自定义菜单链接添加栏目图标</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://blog.imbolo.com/wordpress-insert-a-advertisement-at-the-more-tag/feed/</wfw:commentRss>
		<slash:comments>39</slash:comments>
		</item>
		<item>
		<title>WordPress 高级设置技巧</title>
		<link>http://blog.imbolo.com/wordpress-advance-setting-tips/</link>
		<comments>http://blog.imbolo.com/wordpress-advance-setting-tips/#comments</comments>
		<pubDate>Thu, 29 Apr 2010 15:16:29 +0000</pubDate>
		<dc:creator>bolo</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://blog.imbolo.com/?p=1825</guid>
		<description><![CDATA[WordPress 在编写和修改文章是默认会每隔 60 秒自动保存一次，并且生成一个修订存档，这个设置未必适合每一个人，但后台并没有提供相关的设置。我们可以修改 wp-config.php 里的参数来进行设置。]]></description>
			<content:encoded><![CDATA[<p>WordPress 在编写和修改文章是默认会每隔 60 秒自动保存一次，并且生成一个修订存档，这个设置未必适合每一个人，但后台并没有提供相关的设置。我们可以修改 wp-config.php 里的参数来进行设置。</p>
<h3>修改自动保存间隔时间</h3>
<p>打开 WordPress 根目录里的 wp-config.php(2.9版本在 wp-settings.php 里)，找到以下的代码：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'AUTOSAVE_INTERVAL'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">60</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>这个常量是 WordPress 自动保存的间隔时间，把 60 修改成你想要的秒数即可。<span id="more-1825"></span></p>
<h3>关闭生成修订版功能</h3>
<p>继续查找以下代码：</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: #000088;">$default_constants</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'WP_POST_REVISIONS'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// 如果没有这句的话则查找</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'WP_POST_REVISIONS'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>把 true 改为 false 可以关闭生成修订版本的功能，节省数据库容量 (这个值也可以设置为大于 0 的整数，表示允许生成修订版的最大数量)。 另外，在 WordPress 2.9 以前，还可以查找 <strong>define(&#8216;WP_POST_REVISIONS&#8217;, 3);</strong> 修改 <strong>3</strong> 为修订版的最大数量。</p>
<h3>清空回收站的时间间隔 (2.9)</h3>
<p>WordPress 2.9 里加入了一个回收站功能（Trash），可以把不需要的条目放到回收站里，WordPress 默认每 30 天清空一次回收站。如果你要修改这个间隔的话，可以在 wp-settings.php 里查找以下代码：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'EMPTY_TRASH_DAYS'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">30</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>把 30 修改成你喜欢的天数即可。</p>
<h3>强制使用 SSL 加密登录</h3>
<p>为了增强网站安全性，有很多人都购买了带 SSL 加密的主机。WordPress 从 2.6 开始支持使用 SSL 地址登录后台。查找以下代码：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'FORCE_SSL_ADMIN'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>把 false 修改成 true 可以让管理员使用 SSL 加密协议登录。继续查找以下代码：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'FORCE_SSL_LOGIN'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>把 false 修改成 true 则可以让所有用户都使用 SSL 加密协议登录。</p>
<p  class="related_post_title">Related Posts</p><ul class="related_post"><li><a href="http://blog.imbolo.com/whats-coming-in-wordpress-3-2/" title="WordPress 3.2 新亮点">WordPress 3.2 新亮点</a></li><li><a href="http://blog.imbolo.com/wordpress-3-2-the-plan-faster-lighter/" title="WordPress 3.2 将着重提高效率和程序轻量化">WordPress 3.2 将着重提高效率和程序轻量化</a></li><li><a href="http://blog.imbolo.com/wp-plugin-author-list-plus/" title="适合多人博客的作者列表插件：Author-List-Plus">适合多人博客的作者列表插件：Author-List-Plus</a></li><li><a href="http://blog.imbolo.com/improve-wordpress-navigation-menu-output/" title="为 WordPress 3.0 自定义菜单添加描述">为 WordPress 3.0 自定义菜单添加描述</a></li><li><a href="http://blog.imbolo.com/customizing-the-new-wordpress-3-0-custom-menus-adding-different-icons-to-each-link/" title="为 WordPress 3.0 的自定义菜单链接添加栏目图标">为 WordPress 3.0 的自定义菜单链接添加栏目图标</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://blog.imbolo.com/wordpress-advance-setting-tips/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>WordPress 分享插件：iBegin Share (mod)</title>
		<link>http://blog.imbolo.com/wordpress-plugin-ibegin-share-mod/</link>
		<comments>http://blog.imbolo.com/wordpress-plugin-ibegin-share-mod/#comments</comments>
		<pubDate>Wed, 21 Apr 2010 11:46:12 +0000</pubDate>
		<dc:creator>bolo</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Plugins]]></category>

		<guid isPermaLink="false">http://blog.imbolo.com/?p=1801</guid>
		<description><![CDATA[WordPress 分享插件：iBegin Share (修改版)]]></description>
			<content:encoded><![CDATA[<p><img src="http://i1001.photobucket.com/albums/af131/bolo1988/wordpresspluginiBeginShare.png" alt="WordPress 分享插件：iBegin Share (修改版)" /></p>
<p>因为网络上提供的网址分享插件都没有一个能完全符合我的要求的，所以我曾经想自己做一个分享插件。但得益于 WordPress 繁多的插件，我找到了 <a href="http://wordpress.org/extend/plugins/ibegin-share/" rel="external">iBegin Share</a> 这个插件（在官网下载的插件无法正常运行，因此我制作了一个修改版），它已经满足了我大部分的要求。<span id="more-1801"></span></p>
<h3>特点：</h3>
<ul>
<li>可以自由定义自己喜欢的分享服务</li>
<li>可以对文章被分享的次数进行统计</li>
<li>加载的脚本比较小</li>
<li>不依赖第三方网站运行（提供分享服务的网站除外）</li>
<li>除了分享到其他网络以外，还可以把页面转换成 PDF 或 Word 文档保存到本地</li>
</ul>
<h3>如何使用</h3>
<p>iBegin Share 提供了两种调用方式，他们之间的区别是一种用图片来表示分享按钮，另一种是通过文本方式表示分享按钮。我们可以在模板里通过以下代码调用分享按钮。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span> ?php <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'iBeginShare_TextLink'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
	<span style="color: #339933;">&lt;</span>span id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;share-tool&quot;</span><span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;</span> ?php iBeginShare_TextLink<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> <span style="color: #666666; font-style: italic;">//通过文本方式表示分享按钮</span>
		<span style="color: #666666; font-style: italic;">// 或者</span>
		<span style="color: #339933;">&lt;</span> ?php iBeginShare_Button<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> <span style="color: #666666; font-style: italic;">//通过图片方式表示分享按钮</span>
	<span style="color: #339933;">&lt;/</span>span<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span> ?php <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>两种按钮的效果大家可以自己安装插件测试一下。</p>
<h3>修改版</h3>
<p>由于插件作者在编写插件时写错了一个变量的值，因此大家在官方插件目录里下载的插件是无法运行的。我自己制作了一个修改版，修正了作者的错误，并且用一些国内常用的分享服务代替了一些国外服务。效果如本文配图，国内服务在第一行，国外服务在第二行。大家可以点<a href="http://cantonbolo.googlecode.com/files/ibegin-share.zip">这里下载</a>我修改的版本。</p>
<p  class="related_post_title">Related Posts</p><ul class="related_post"><li><a href="http://blog.imbolo.com/wp-plugin-author-list-plus/" title="适合多人博客的作者列表插件：Author-List-Plus">适合多人博客的作者列表插件：Author-List-Plus</a></li><li><a href="http://blog.imbolo.com/diy-a-plugin/" title="做一个自己的插件">做一个自己的插件</a></li><li><a href="http://blog.imbolo.com/wordpress-plugin-admin-post-navigation/" title="插件推荐：Admin Post Navigation">插件推荐：Admin Post Navigation</a></li><li><a href="http://blog.imbolo.com/overlay4wp/" title="WordPress相册插件：Overlay4WP">WordPress相册插件：Overlay4WP</a></li><li><a href="http://blog.imbolo.com/whats-coming-in-wordpress-3-2/" title="WordPress 3.2 新亮点">WordPress 3.2 新亮点</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://blog.imbolo.com/wordpress-plugin-ibegin-share-mod/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>做一个自己的插件</title>
		<link>http://blog.imbolo.com/diy-a-plugin/</link>
		<comments>http://blog.imbolo.com/diy-a-plugin/#comments</comments>
		<pubDate>Tue, 16 Feb 2010 06:58:28 +0000</pubDate>
		<dc:creator>bolo</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Plugins]]></category>

		<guid isPermaLink="false">http://blog.imbolo.com/?p=1696</guid>
		<description><![CDATA[很多人在换主题时首先做的是修改一下，例如加上自己的站点统计代码，或者加上自己的个性功能等等。如果我们把这些功能都做成一个插件，那样我们在换主题时就可以省很多功夫。]]></description>
			<content:encoded><![CDATA[<p>很多人在换主题时首先做的是修改一下，例如加上自己的站点统计代码，或者加上自己的个性功能等等。如果我们把这些功能都做成一个插件，那样我们在换主题时就可以省很多功夫。这篇文章浅浅睇说一下如何做一个你自己的插件。</p>
<p>首先建一个bolo.php文件，在里面写上下面的代码：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span> ?php
<span style="color: #666666; font-style: italic;">/*
Plugin Name: bolo
Plugin URI: http://imbolo.com
Description: Bolo's custom plugin
Version: 1.0
Author URI: http://blog.imbolo.com
*/</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>把这个文件放进一个叫bolo的文件夹里，上传到plugins目录后就可以在后台激活。这就是一个最简单的插件了，什么功能都没有。下面我就加一些功能。<span id="more-1696"></span></p>
<h3>添加站点统计</h3>
<p>站点统计是每个站长都会使用的工具，每天都不能少，通过插件来添加站点统计，免除了手动修改主题的麻烦。代码也非常简单。</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: #000000; font-weight: bold;">function</span> site_analytics<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'此处替换成你的统计代码'</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;">'wp_footer'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'site_analytics'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>把上面的代码插入到bolo.php里，统计代码就会自动添加到主题模板wp_footer()的地方。</p>
<h3>移除某些插件的CSS和JS</h3>
<p>很多插件在激活以后会在主题模板的wp_head()和wp_footer()这两个地方添加自己的CSS和JS，这样会增加HTTP请求数。因此我们在合并了插件的CSS和JS文件后需要移除这些Hook，防止作用相同的文件重复加载，我们可以用下面的代码轻松搞定。</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;">remove_action<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'wp_head'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'插件的Hook'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//移除header里的某个Hook</span>
remove_action<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'wp_footer'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'插件的Hook'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//移除footer里的某个Hook</span></pre></td></tr></table></div>

<h3>后记</h3>
<p>以上两个举例希望可以起到抛砖引玉的作用，要开发更多的功能，可以参考一下《<a href="http://blog.imbolo.com/leave-a-improve-place/">预留改进的空间</a>》这篇文章。很多人喜欢吧一些小功能写进主题的functions.php里，我个人认为把这些功能都做成一个独立的插件是一个更好的办法。虽然精确地说整个网站的运行速度是会慢那么很微小的一点点，但那几毫秒的时间省下来了你又能干些什么？如果非要追求速度，把页面缓存成html文件就没有差别了。</p>
<p  class="related_post_title">Related Posts</p><ul class="related_post"><li><a href="http://blog.imbolo.com/wp-plugin-author-list-plus/" title="适合多人博客的作者列表插件：Author-List-Plus">适合多人博客的作者列表插件：Author-List-Plus</a></li><li><a href="http://blog.imbolo.com/wordpress-plugin-ibegin-share-mod/" title="WordPress 分享插件：iBegin Share (mod)">WordPress 分享插件：iBegin Share (mod)</a></li><li><a href="http://blog.imbolo.com/wordpress-plugin-admin-post-navigation/" title="插件推荐：Admin Post Navigation">插件推荐：Admin Post Navigation</a></li><li><a href="http://blog.imbolo.com/overlay4wp/" title="WordPress相册插件：Overlay4WP">WordPress相册插件：Overlay4WP</a></li><li><a href="http://blog.imbolo.com/whats-coming-in-wordpress-3-2/" title="WordPress 3.2 新亮点">WordPress 3.2 新亮点</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://blog.imbolo.com/diy-a-plugin/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
		<item>
		<title>预留改进的空间</title>
		<link>http://blog.imbolo.com/leave-a-improve-place/</link>
		<comments>http://blog.imbolo.com/leave-a-improve-place/#comments</comments>
		<pubDate>Tue, 09 Feb 2010 07:35:33 +0000</pubDate>
		<dc:creator>bolo</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Shortcode]]></category>

		<guid isPermaLink="false">http://blog.imbolo.com/?p=1682</guid>
		<description><![CDATA[在做我的音乐博客 NoSay.in时我曾经考虑了很多日后进行更新时会遇到的问题]]></description>
			<content:encoded><![CDATA[<p>在做我的<a href="http://nosay.in" rel="external">音乐博客 NoSay.in</a>时我曾经考虑了很多日后进行更新时会遇到的问题，例如：以后我想在首页增加一个快速听歌的功能，因此我在每篇日志里都预先写上了custom field；还有某些对用户体验产生很大影响的插件，以后在更换插件的时候，我如何才能使对用户和我自己的影响降到最低？因此我当时选择了一些使用简便的插件。但昨天我看了wordpress.la的<a href="http://www.wordpress.la/shortcodes.html" rel="external">《精通 WordPress简码》</a>后，一个更好的想法诞生了。<span id="more-1682"></span></p>
<h3>什么是Short Code？</h3>
<p>WordPress Short Code也叫做短代码或者短码，早在WP2.5里已经加入了这个功能。WP短码在功能上和做主题和插件时经常做的自定义function功能几乎一样，也支持自定义参数。最大的区别是WP短码可以在文章里通过自定义的标记进行调用，具有极高的灵活性。请看摘自wordpress.la的一个例子。</p>
<blockquote><p>
定制Google AdSense位置</p>
<p>问题：许多博主都在使用Google AdSense，在主题文件如sidebar.php 添加AdSense编码非常容易，但有经验的网络营销师都明白访客点击最多的还是嵌入在文章内部的广告。</p>
<p>解决方案：若在日志或页面中嵌入AdSense广告，需创建以下简码：</p>
<p>   1. 打开functions.php文件并复制以下代码。记得把JavaScript代码换成自己的AdSense代码。<br />
      function showads() {<br />
          return &#8216;
<div id="adsense"><script type="text/javascript"><!--
          google_ad_client = "pub-XXXXXXXXXXXXXX";
          google_ad_slot = "4668915978";
          google_ad_width = 468;
          google_ad_height = 60;
          //-->
      </script><br />
      <script type="text/javascript"
      src="http://88.198.60.17/images/mastering-wordpress-shortcodes/http://pagead2.googlesyndication.com/pagead/show_ads.js">
      </script></div>
<p>&#8216;;<br />
      }<br />
      add_shortcode(&#8216;adsense&#8217;, &#8216;showads&#8217;);<br />
   2. 保存functions.php文件后，可使用以下简码在日志和页面定制AdSense显示位置：<br />
      &#91;adsense&#93;</p>
<p>注意AdSense代码被adsense div元素包装，这样我们就可以在style.css文件中设计其样式。</p>
<p>代码注释：以上代码用来显示AdSense广告。当把简码插入日志中时，它就会返回AdSense广告。这一切都非常简单，同时也节省了大量时间。
</p></blockquote>
<p>从这个例子可以看到，通过WP短码，我们可以在文章里的任意一个地方快速地插入一段已经定制好的代码。这将大大地提升你的工作效率。</p>
<h3>如何预留改进的空间？</h3>
<p>首先说说我的看法。我预留改进的空间的原因是我要避免被“插件劫持”。插件劫持是我自己命名的一种情况，意思是你正在使用一个前台插件，例如<a href="http://highslide.com/" rel="external">Hightslide</a>，要正常使用Highslide的功能的话，我就必须在文章里使用符合Hightslide的规则的代码。麻烦就从这里开始。到了后来的某一天，我觉得<a href="http://www.magictoolbox.com" rel="external">Magic Toolbox</a>更好，于是乎我转用Magic Toolbox，可是Magic Toolbox和Hightslide的调用代码不兼容，于是我又要重新修改以前写的文章，使旧文章也支持Magic Toolbox。考虑到旧文章的兼容问题，于是我可能嫌麻烦，而被迫继续使用Hightslide。这就是所谓的插件劫持。而WP短码正好可以解决这个问题。以下是我想到的解决插件劫持问题的方法。</p>
<p>在使用Hightslide的时候，我先在主题的function.php里定义一个短码。</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: #000000; font-weight: bold;">function</span> insert_img<span style="color: #009900;">&#40;</span><span style="color: #000088;">$atts</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #990000;">extract</span><span style="color: #009900;">&#40;</span>shortcode_atts<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
<span style="color: #0000ff;">&quot;href&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'http://'</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$atts</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">'&lt;a href=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$href</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' class=&quot;highslide&quot; onclick=&quot;return hs.expand(this)&quot;&gt;&lt;img src=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$content</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; alt=&quot;Highslide JS&quot;/&gt;&lt;/a&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
add_shortcode<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;img&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;insert_img&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>这样我就能通过在文章里插入&#91;img href=&#8221;big.jpg&#8221;&#93;small.jpg&#91/img&#93;这样的代码来插入带有Hightslide效果的图片。当我转用Magic Toolbox后，我只需要把短码修改一下，变成：</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: #000000; font-weight: bold;">function</span> insert_img<span style="color: #009900;">&#40;</span><span style="color: #000088;">$atts</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #990000;">extract</span><span style="color: #009900;">&#40;</span>shortcode_atts<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
<span style="color: #0000ff;">&quot;href&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'http://'</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$atts</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">'&lt;a href=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$href</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; class=&quot;MagicThumb&quot;&gt;&lt;img src=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$content</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; alt=&quot;&quot;/&gt;&lt;/a&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
add_shortcode<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;img&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;insert_img&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>通过修改一次代码，我所有采用WP短码插入的Highslide效果都将转变成Magic Toolbox的效果。同样的，如果想在Magic Toolbox的基础上再进行改变，我也是只需要修改我定义的WP短码就可以了。</p>
<h3>后记</h3>
<p>对很多刚开始用WordPress的人来说，大多数人是不会注重以后的升级的（包括我），这也造成很多人在文章多了以后遇到了插件劫持。我希望看过这篇文章的朋友都能重视这个问题，并在以后的日子里尽量避开它。虽然在开始的时候会麻烦点，但能对以后的更新带来很大的方便。</p>
<p>另外提醒一下，用WP短码来进行不同插件的过渡的方法只使用于完全由浏览器实现效果的插件，对需要在后台进行二次处理的插件是无效的，如WP-Syntax。</p>
<p>本文所用的例子不能代表Hightslide和Magic Toolbox在实际使用上的优劣，请大家根据自己的情况自行选用插件。</p>
<p  class="related_post_title">Related Posts</p><ul class="related_post"><li><a href="http://blog.imbolo.com/whats-coming-in-wordpress-3-2/" title="WordPress 3.2 新亮点">WordPress 3.2 新亮点</a></li><li><a href="http://blog.imbolo.com/wordpress-3-2-the-plan-faster-lighter/" title="WordPress 3.2 将着重提高效率和程序轻量化">WordPress 3.2 将着重提高效率和程序轻量化</a></li><li><a href="http://blog.imbolo.com/wp-plugin-author-list-plus/" title="适合多人博客的作者列表插件：Author-List-Plus">适合多人博客的作者列表插件：Author-List-Plus</a></li><li><a href="http://blog.imbolo.com/improve-wordpress-navigation-menu-output/" title="为 WordPress 3.0 自定义菜单添加描述">为 WordPress 3.0 自定义菜单添加描述</a></li><li><a href="http://blog.imbolo.com/customizing-the-new-wordpress-3-0-custom-menus-adding-different-icons-to-each-link/" title="为 WordPress 3.0 的自定义菜单链接添加栏目图标">为 WordPress 3.0 的自定义菜单链接添加栏目图标</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://blog.imbolo.com/leave-a-improve-place/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>

