<?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>網生@誌 &#124; zEUS.&#039;Blog &#187; cat icons</title>
	<atom:link href="http://zeuscn.net/index.php/archives/tag/cat-icons/feed" rel="self" type="application/rss+xml" />
	<link>http://zeuscn.net</link>
	<description>Not Only Wordpress Template, But Also My Life...</description>
	<lastBuildDate>Tue, 03 Jan 2012 13:20:32 +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 显示分类图片的补充</title>
		<link>http://zeuscn.net/archives/2008/09/10/wordpress-category-icon-plus.html</link>
		<comments>http://zeuscn.net/archives/2008/09/10/wordpress-category-icon-plus.html#comments</comments>
		<pubDate>Wed, 10 Sep 2008 13:02:25 +0000</pubDate>
		<dc:creator>zEUS.</dc:creator>
				<category><![CDATA[Wordpress研究]]></category>
		<category><![CDATA[cat icons]]></category>
		<category><![CDATA[category icons]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[分类图标]]></category>

		<guid isPermaLink="false">http://zeuscn.net/?p=485</guid>
		<description><![CDATA[骑车回家的路上突然冒出了个想法，回来一试还果真成功... 小有成就感 :grin: 

在 <a href="http://zeuscn.net/archives/2008/09/10/wordpress-category-icon/" target="_blank" />Wordpress 技巧—显示分类图片</a> 一文中我大致介绍了如何让文章所属的分类图片显示在文章旁边的方法，其调用代码借鉴自国外的 Wordpress 高手：
虽然我不是很懂 PHP ，但大致能理解上述代码的作用（理解如果有误，请指正）：
第一行调用 Wordpress 默认的分类函数并起了一个别名 <strong>$cat</strong>
<p><span class="readmore"><a href="http://zeuscn.net/archives/2008/09/10/wordpress-category-icon-plus/" title="Wordpress 显示分类图片的补充">阅读全文——共656字</a></span></p>]]></description>
			<content:encoded><![CDATA[<p>骑车回家的路上突然冒出了个想法，回来一试还果真成功&#8230; 小有成就感 <img src='http://zeuscn.net/wp-includes/images/smilies/icon_biggrin.gif' alt=':grin:' class='wp-smiley' />  </p>
<p>在 <a href="http://zeuscn.net/archives/2008/09/10/wordpress-category-icon/" target="_blank" />WordPress 技巧—显示分类图片</a> 一文中我大致介绍了如何让文章所属的分类图片显示在文章旁边的方法，其调用代码借鉴自国外的 <a href="http://zeuscn.net/archives/tag/wordpress" class="st_tag internal_tag" rel="tag" title="标签 wordpress 下的日志">WordPress</a> 高手：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>get_the_category<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$cat</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #000088;">$catname</span> <span style="color: #339933;">=</span><span style="color: #000088;">$cat</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">category_nicename</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;</span>span id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;more-485&quot;</span><span style="color: #339933;">&gt;&lt;/</span>span<span style="color: #339933;">&gt;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;a href=/category/&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$catname</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;/&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;img src=http://yourdomain/wp-content/cat-icons/&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$catname</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;.jpg alt=<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #006699; font-weight: bold;">$catname</span> category <span style="color: #000099; font-weight: bold;">\&quot;</span> title=<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #006699; font-weight: bold;">$catname</span> 分类 <span style="color: #000099; font-weight: bold;">\&quot;</span> /&gt;&lt;/a&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>虽然我不是很懂 <a href="http://zeuscn.net/archives/tag/php" class="st_tag internal_tag" rel="tag" title="标签 php 下的日志">PHP</a> ，但大致能理解上述代码的作用（理解如果有误，请指正）：<br />
第一行调用 WordPress 默认的分类函数并起了一个别名 <strong>$cat</strong><br />
第三行将函数中的 <strong>category_nicename 分类缩略名变量</strong>赋值给 <strong>$catname</strong><br />
下面的几行就是输出图像链接和拼接。<br />
看到倒数第三行中的 <strong>title=\”$catname 分类 \”</strong> ，这是输出图片的 title 属性，也就是我们鼠标移动到图片上所出现的简介文字。<br />
由于我们使用中文分类名和英文缩略名，所以这里的 <strong>title 输出的并不是分类的名称，而是一串英文缩略名</strong>。这种效果对于中文来说这并不合适，所以我就想到何不仿造 $catname 来做个 $cattitle 以实现下图的效果呢？</p>
<p align=center><img src="http://pic.yupoo.com/zeuscn/2863162b31f1/medium.jpg" alt="wordpress, 分类图片" title="wordpress, 分类图片" /></p>
<p>那么现在的问题是如何获取 WordPress 分类函数里<strong>定义分类名称的变量</strong>呢？</p>
<p>此时就轮到 Firefox 的著名插件 Firebug 登场了～<br />
进入 WordPress 后台-管理-分类，使用 Firebug 查看元素属性和样式，于是我就轻而易举的得到了我想要的变量名：</p>
<p align=center><img src="http://pic.yupoo.com/zeuscn/9524762b3a1d/1ungb105.jpg" alt="wordpress, 分类图片" title="wordpress, 分类图片" /></p>
<p><strong>cat_name</strong> 这个变量即是我们的目标～ 找到对应的变量名之后，代码稍作修改即可（增加一个变量：$cattitle 和修改 title 的值：\”$cattitle\ ）：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>get_the_category<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$cat</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #000088;">$catname</span> <span style="color: #339933;">=</span><span style="color: #000088;">$cat</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">category_nicename</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$cattitle</span><span style="color: #339933;">=</span><span style="color: #000088;">$cat</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cat_name</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;a href=/category/&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$catname</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;/&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;img src=http://yourdomain/wp-content/cat-icons/&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$catname</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;.jpg alt=<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #006699; font-weight: bold;">$catname</span> category <span style="color: #000099; font-weight: bold;">\&quot;</span> title=<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #006699; font-weight: bold;">$cattitle</span><span style="color: #000099; font-weight: bold;">\&quot;</span> /&gt;&lt;/a&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Ok , that &#8216;s all~~ 修改完毕，这样整个效果就基本完美了</p>
<p align=right>zEUS.</p>
<hr /><h2>日志评论</h2><ul><li><a href="http://zeuscn.net/archives/2008/09/10/wordpress-category-icon-plus.html">2008年, 九月 10日</a>, <a href='http://www.eemir3.com' rel='external nofollow' class='url'>Yacca</a> writes: 据说是沙发么...好吧  继续学习
今天要写半年工作计划...明天交掉了慢慢学习
我要减少自己的首页图片量...</li><li><a href="http://zeuscn.net/archives/2008/09/10/wordpress-category-icon-plus.html">2008年, 九月 10日</a>, <a href='http://zeuscn.net/' rel='external nofollow' class='url'>zEUS.</a> writes: @Yacca：还好～ 没有我的多  :razz:</li><li><a href="http://zeuscn.net/archives/2008/09/10/wordpress-category-icon-plus.html">2008年, 九月 11日</a>, <a href='http://www.gtalkme.com' rel='external nofollow' class='url'>fiorano</a> writes: 我已经没兴趣研究这东西了。。。不过好在你喜欢研究，哈哈！ :mrgreen:</li><li><a href="http://zeuscn.net/archives/2008/09/10/wordpress-category-icon-plus.html">2008年, 九月 11日</a>, <a href='http://zeuscn.net' rel='external nofollow' class='url'>zEUS.</a> writes: 呵呵，是啊，打算以后主攻这个了...</li><li><a href="http://zeuscn.net/archives/2008/09/10/wordpress-category-icon-plus.html">2008年, 九月 11日</a>, <a href='http://zeuscn.net/' rel='external nofollow' class='url'>zEUS.</a> writes: 测试是否会发送邮件～</li><li><a href="http://zeuscn.net/archives/2008/09/10/wordpress-category-icon-plus.html">2008年, 九月 11日</a>, <a href='http://www.wodidai.com' rel='external nofollow' class='url'>花果山寨</a> writes: PHP就是好，简单的几句代码就搞定！</li><li><a href="http://zeuscn.net/archives/2008/09/10/wordpress-category-icon-plus.html">2008年, 九月 12日</a>, <a href='http://www.freerainbow.cn' rel='external nofollow' class='url'>freesky</a> writes: 说实话，真没看懂，惭愧还要多学习！</li><li><a href="http://zeuscn.net/archives/2008/09/10/wordpress-category-icon-plus.html">2008年, 九月 12日</a>, <a href='http://zeuscn.net' rel='external nofollow' class='url'>zEUS.</a> writes: :?: 其实我觉得我的表达也不是很清楚...</li><li><a href="http://zeuscn.net/archives/2008/09/10/wordpress-category-icon-plus.html">2008年, 九月 19日</a>, <a href='http://seo-dic.com.cn' rel='external nofollow' class='url'>美丽星点</a> writes: zEus.真是把firebug的作用发挥到了极致了，</li><li><a href="http://zeuscn.net/archives/2008/09/10/wordpress-category-icon-plus.html">2008年, 十月 30日</a>, <a href='http://www.mybudai.com/10-rare-classical-techniques-wordpress.html' rel='external nofollow' class='url'>10＋少见的Wordpress经典技巧 | 诸葛布袋</a> writes: [...] WordPress 显示分类图片的补充 [...]</li><li><a href="http://zeuscn.net/archives/2008/09/10/wordpress-category-icon-plus.html">2008年, 十一月 2日</a>, <a href='http://tailog.com' rel='external nofollow' class='url'>Centeur</a> writes: 这个方法还比较巧妙。 :mrgreen:</li><li><a href="http://zeuscn.net/archives/2008/09/10/wordpress-category-icon-plus.html">2008年, 十二月 1日</a>, <a href='http://51blog.co.cc/2008/add-category-icon-for-template.html' rel='external nofollow' class='url'>我要博客 &raquo; 内容索引 &raquo; 为WordPress主题添加分类图标 - 网络 知识 分享 生活</a> writes: [...] 可正如原作者在Wordpress 显示分类图片的补充一文中所言，如上的代码还略有不足，主要是鼠标悬停于图标上时，显示的文字不是我们设置的汉字分类，而是我们设置的分类的英文缩写。原作者将上面的代码修改如下： [...]</li><li><a href="http://zeuscn.net/archives/2008/09/10/wordpress-category-icon-plus.html">2008年, 十二月 25日</a>, <a href='http://www.jie-meng.cn' rel='external nofollow' class='url'>周公解梦</a> writes: 谢谢你啊，这个我学习了。。</li><li><a href="http://zeuscn.net/archives/2008/09/10/wordpress-category-icon-plus.html">2009年, 三月 5日</a>, <a href='http://wzhjk.420mb.com/?p=41' rel='external nofollow' class='url'>淘友 &raquo; 为WordPress主题添加分类图标</a> writes: [...] 可正如原作者在Wordpress 显示分类图片的补充一文中所言，如上的代码还略有不足，主要是鼠标悬停于图标上时，显示的文字不是我们设置的汉字分类，而是我们设置的分类的英文缩写。原作者将上面的代码修改如下： [...]</li><li><a href="http://zeuscn.net/archives/2008/09/10/wordpress-category-icon-plus.html">2009年, 四月 14日</a>, <a href='http://www.xsean.cn' rel='external nofollow' class='url'>Sean</a> writes: &lt;?php foreach((get_the_category()) as $cat) 这句不是起别名的，是用来遍历数组的 也就是说从数组 (get_the_category()中取数据。</li><li><a href="http://zeuscn.net/archives/2008/09/10/wordpress-category-icon-plus.html">2009年, 四月 14日</a>, <a href='http://zeuscn.net/' rel='external nofollow' class='url'>zEUS.</a> writes: 多谢指正，遍历应该是 foreach() 这句，as $cat 应该是把遍历的结果丢到 $cat 这个变量里了。不知道我这样理解对不对...</li><li><a href="http://zeuscn.net/archives/2008/09/10/wordpress-category-icon-plus.html">2009年, 四月 26日</a>, <a href='http://yangtx.com' rel='external nofollow' class='url'>Yangtx</a> writes: 正有此打算。很久没来了，变化不小。</li><li><a href="http://zeuscn.net/archives/2008/09/10/wordpress-category-icon-plus.html">2009年, 九月 30日</a>, <a href='http://blog.xbadan.cn/html/2009/09/30/507.html' rel='external nofollow' class='url'>WordPress 显示分类图片 &laquo; 居龙闲志</a> writes: [...] 显示分类图片    daitui.init();    转至 網生@誌網生@誌  WordPress 显示分类图片          [...]</li></ul><hr /><p>本文地址：<a href="http://zeuscn.net/archives/2008/09/10/wordpress-category-icon-plus.html">http://zeuscn.net/archives/2008/09/10/wordpress-category-icon-plus.html</a>，转载原创文章请注明 <a href="http://zeuscn.net/">zEUScn.NET</a> ‖
      您可以直接 <a href="http://zeuscn.net/archives/2008/09/10/wordpress-category-icon-plus.html#comments"title="to the comments">发布评论</a>
      </p>
    <p>Copyright©<a href="%%blogurl%%">zEUScn.NET</a>.Some rights reserved.</p>
(Digital Fingerprint:<br /> 05538bd2e0492fe803256b5788cfa6fd)
	<ul class="st-related-posts">
	<li><a href="http://zeuscn.net/archives/2008/07/25/plans-of-wordpress-themes-2.html" title="近期关于 WordPress 主题的一些计划 (2008年, 七月 25日)">近期关于 WordPress 主题的一些计划</a> (23)</li>
	<li><a href="http://zeuscn.net/archives/2007/08/02/wp-background-chinese.html" title="wordpress后台无法汉化的解决办法 (2007年, 八月 2日)">wordpress后台无法汉化的解决办法</a> (11)</li>
	<li><a href="http://zeuscn.net/archives/2007/12/13/wow-theme-cn.html" title="WOW Theme &mdash; 魔兽风格的 WordPress 主题模板！ (2007年, 十二月 13日)">WOW Theme &mdash; 魔兽风格的 WordPress 主题模板！</a> (28)</li>
	<li><a href="http://zeuscn.net/archives/2007/08/26/wordpresstheme-pink-kupy.html" title="wordpress模板：pink-kupy-10 (2007年, 八月 26日)">wordpress模板：pink-kupy-10</a> (7)</li>
	<li><a href="http://zeuscn.net/archives/2007/12/11/why-wordpress-themes.html" title="Why WordPress Themes (2007年, 十二月 11日)">Why WordPress Themes</a> (8)</li>
	<li><a href="http://zeuscn.net/archives/2007/11/10/making-another-wp-theme.html" title="又一个 WordPress 主题全力制作中&#8230; (2007年, 十一月 10日)">又一个 WordPress 主题全力制作中&#8230;</a> (9)</li>
	<li><a href="http://zeuscn.net/archives/2008/02/27/ipple-utral-beta.html" title="ipple utral beta 上线试运行 (2008年, 二月 27日)">ipple utral beta 上线试运行</a> (23)</li>
	<li><a href="http://zeuscn.net/archives/2008/10/01/dztheme-update.html" title="DZTHEME.COM 一期改版完成 (2008年, 十月 1日)">DZTHEME.COM 一期改版完成</a> (22)</li>
	<li><a href="http://zeuscn.net/archives/2008/05/04/wp-grins-and-theme-switcher.html" title="WordPress 表情插件和主题切换插件 (2008年, 五月 4日)">WordPress 表情插件和主题切换插件</a> (28)</li>
	<li><a href="http://zeuscn.net/archives/2007/12/13/plans-of-wordpress-themes.html" title="WordPress 主题计划 (2007年, 十二月 13日)">WordPress 主题计划</a> (101)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://zeuscn.net/archives/2008/09/10/wordpress-category-icon-plus.html/feed</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>WordPress 技巧—显示分类图片</title>
		<link>http://zeuscn.net/archives/2008/09/10/wordpress-category-icon.html</link>
		<comments>http://zeuscn.net/archives/2008/09/10/wordpress-category-icon.html#comments</comments>
		<pubDate>Wed, 10 Sep 2008 06:12:06 +0000</pubDate>
		<dc:creator>zEUS.</dc:creator>
				<category><![CDATA[Wordpress研究]]></category>
		<category><![CDATA[cat icons]]></category>
		<category><![CDATA[category icons]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[分类图标]]></category>

		<guid isPermaLink="false">http://zeuscn.net/?p=483</guid>
		<description><![CDATA[何为分类图片？——我们的每篇日志都有自己的分类，一般来说在文章栏中我们会用文字链接来描述文章所属分类，但有时候出于美观和页面整体效果的需要我们要用不同的图片来代替各种分类。那么如何来达到这种效果呢？ 其实 WordPress 已经有了个叫做 Category Icons 的插件可以帮助我们在文章需要的地方显示分类图片，并且还能显示在 Feed 中，该插件还提供一些其它的功能。可惜的是插件作者主页国内无法访问，我找不到详细的使用说明文档，无奈只有放弃这款插件。 在继续搜寻互联网之后，我寻找到了另外一种同样非常有效方法——不用插件也能显示分类图片！该方法基于 Styling Posts by Category and Category-Specific Images 并修改自 Very Easy WordPress Theme Hack: Show Category Images ，下面我来谈谈我是如何在博客首页上实现这个效果的，效果如下图： 准备好各个对应分类的图片，并且图片的名称需要和分类名一致！比如我有一个 “与我有关” 的文章分类，其缩略名是 “sth-about-me” ，那么我就将对应的分类图片命名为 “sth-about-me.jpg” （进入 WordPress 后台-管理-分类，即可修改分类缩略名，最好使用英文）。 使用 FTP 在你的 /wp-contant/ 目录下建立一个 cat-icons 目录，将所有分类图片上传至该目录下。 打开你的 index.php 文件，在 post 容器内，即 1 2 &#60;div class=&#34;post&#34; id=&#34;post-&#60;?php the_ID(); ?&#62;&#34;&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>何为分类图片？——我们的每篇日志都有自己的分类，一般来说在文章栏中我们会用文字链接来描述文章所属分类，但有时候出于美观和页面整体效果的需要我们要用不同的图片来代替各种分类。那么如何来达到这种效果呢？</p>
<p>其实 <a href="http://zeuscn.net/archives/tag/wordpress" class="st_tag internal_tag" rel="tag" title="标签 wordpress 下的日志">WordPress</a> 已经有了个叫做 <a href="http://wordpress.org/extend/plugins/category-icons/" target="_blank" />Category Icons</a> 的插件可以帮助我们在文章需要的地方显示分类图片，并且还能显示在 Feed 中，该插件还提供一些其它的功能。可惜的是插件作者主页国内无法访问，我找不到详细的使用说明文档，无奈只有放弃这款插件。</p>
<p>在继续搜寻互联网之后，我寻找到了另外一种同样非常有效方法——不用插件也能显示分类图片！<span id="more-483"></span>该方法基于 <a href="http://www.wpdesigner.com/2007/06/22/styling-posts-by-category-and-category-specific-images/" target="_blank" />Styling Posts by Category and Category-Specific Images</a> 并修改自 <a href="http://www.jtpratt.com/very-easy-wordpress-theme-hack-show-category-images/" target="_blank" />Very Easy WordPress Theme Hack: Show Category Images</a> ，下面我来谈谈我是如何在博客首页上实现这个效果的，效果如下图：</p>
<p align=center><img src="http://pic.yupoo.com/zeuscn/1577362acf96/medium.jpg" alt="ZEUS." class="img_border" /></p>
<ol>
<li>准备好各个对应分类的图片，并且<strong>图片的名称需要和分类名一致</strong>！比如我有一个 “与我有关” 的文章分类，其缩略名是 “sth-about-me” ，那么我就将对应的分类图片命名为 “sth-about-me.jpg” （进入 WordPress 后台-管理-分类，即可修改分类缩略名，<strong>最好使用英文</strong>）。</li>
<li>使用 FTP 在你的 /wp-contant/ 目录下建立一个 cat-icons 目录，将所有分类图片上传至该目录下。</li>
<li>打开你的 index.<a href="http://zeuscn.net/archives/tag/php" class="st_tag internal_tag" rel="tag" title="标签 php 下的日志">php</a> 文件，在 post 容器内，即

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="css" style="font-family:monospace;">&lt;div class<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;post&quot;</span> id<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;post-&lt;?php the_ID(); ?&gt;&quot;</span><span style="color: #00AA00;">&gt;</span>
&lt;/div<span style="color: #00AA00;">&gt;</span></pre></td></tr></table></div>

<p>之中的适当位置添加如下代码：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>get_the_category<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$cat</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #000088;">$catname</span> <span style="color: #339933;">=</span><span style="color: #000088;">$cat</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">category_nicename</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;a href=/category/&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$catname</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;/&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;img src=http://yourdomain/wp-content/cat-icons/&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$catname</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;.jpg alt=<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #006699; font-weight: bold;">$catname</span> category <span style="color: #000099; font-weight: bold;">\&quot;</span> title=<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #006699; font-weight: bold;">$catname</span> 分类 <span style="color: #000099; font-weight: bold;">\&quot;</span> /&gt;&lt;/a&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>我想稍懂 HTML 和 PHP 的朋友应该能理解上述语句的含义，但请注意，倘若你的分类永久链接形式不是默认的： “<strong>http://yourdomain/category/分类名称/</strong>” 那么你就需要根据自己的链接形式修改第四行的 “<strong>/category/</strong>” </li>
<li>最后你还需要有一定的 HTML/<a href="http://zeuscn.net/archives/tag/css" class="st_tag internal_tag" rel="tag" title="标签 css 下的日志">CSS</a> 的知识来将上述代码进行定位，你可以让它在 “entry 容器” 旁 float left 或者 right ，如果图片较小的话还能放到文章标题 H2 的旁边等等，这就要看大家的想象力和页面的排版方式了。</li>
</ol>
<p>完成上述步骤后，分类图片就能自动的添加在文章旁了。有个问题还需要注意，如果你的文章不止属于一个分类，此时对应的所有分类图片都会显示，如果你的版式和我一样只想让它显示一个分类图标的话就需要用 CSS 技巧来 hiden 多余的图片了。根据不同的样式其方法也不一样，所以我也不进行说明了。</p>
<p>比起安装插件，这个方法要更加简洁！也更推荐大家使用～ 不过如果你对 PHP HTML/CSS 相关知识还一无所知的话，就需要慎用了&#8230;</p>
<p align=right>zEUS.</P></p>
<hr /><h2>日志评论</h2><ul><li><a href="http://zeuscn.net/archives/2008/09/10/wordpress-category-icon.html">2008年, 九月 10日</a>, <a href='http://www.dogorgod.com/' rel='external nofollow' class='url'>dogorgod</a> writes: 哈哈，这么快就制作好了啊～效果不错
真是骇客的技巧，好好学习一下 :smile:</li><li><a href="http://zeuscn.net/archives/2008/09/10/wordpress-category-icon.html">2008年, 九月 10日</a>, <a href='http://booto.net' rel='external nofollow' class='url'>Love CJ</a> writes: :mrgreen: 顶老大哈。。。这个好教程！</li><li><a href="http://zeuscn.net/archives/2008/09/10/wordpress-category-icon.html">2008年, 九月 10日</a>, <a href='http://zeuscn.net/archives/2008/09/10/wordpress-category-icon-plus/' rel='external nofollow' class='url'>WordPress 显示分类图片的补充 | 網生@誌 | zEUS.'Blog</a> writes: [...] WordPress 技巧—显示分类图片 [...]</li><li><a href="http://zeuscn.net/archives/2008/09/10/wordpress-category-icon.html">2008年, 九月 10日</a>, <a href='http://zeuscn.net/' rel='external nofollow' class='url'>zEUS.</a> writes: @dogorgod：是啊，呵呵，可是样式我觉得还不是很完美，dogorogod 兄何时设计一下？
@Love CJ：不敢当啊... 我还不是很老呢...</li><li><a href="http://zeuscn.net/archives/2008/09/10/wordpress-category-icon.html">2008年, 九月 10日</a>, <a href='http://www.eemir3.com' rel='external nofollow' class='url'>Yacca</a> writes: 最近考虑着要更新首页...嗯 分类图片的确是个办法...</li><li><a href="http://zeuscn.net/archives/2008/09/10/wordpress-category-icon.html">2008年, 九月 11日</a>, <a href='http://www.wodidai.com' rel='external nofollow' class='url'>花果山寨</a> writes: 这样的效果还真不错</li><li><a href="http://zeuscn.net/archives/2008/09/10/wordpress-category-icon.html">2008年, 九月 11日</a>, <a href='http://zeuscn.net/' rel='external nofollow' class='url'>zEUS.</a> writes: 不过分类图片会增加首页的负担哦～</li><li><a href="http://zeuscn.net/archives/2008/09/10/wordpress-category-icon.html">2008年, 九月 12日</a>, <a href='http://www.eemir3.com' rel='external nofollow' class='url'>Yacca</a> writes: 对我而言...我本来就在首页加图滴,无所谓了...

昨天考虑了下,找不到浑然统一的分类图...郁闷 先不换了...</li><li><a href="http://zeuscn.net/archives/2008/09/10/wordpress-category-icon.html">2008年, 九月 15日</a>, <a href='http://jobru.net' rel='external nofollow' class='url'>JoBru</a> writes: :mrgreen: 很好很强大～～！！

Category Icons用代理倒可以上，不过还是大大说的方法简便～～</li><li><a href="http://zeuscn.net/archives/2008/09/10/wordpress-category-icon.html">2008年, 十月 9日</a>, <a href='http://www.appinn.com' rel='external nofollow' class='url'>scavin</a> writes: 主页打不开可以翻墙啊。。。

这年头上网，什么不会，不能不会翻墙啊

去 google 搜索 tor 就有结果了</li><li><a href="http://zeuscn.net/archives/2008/09/10/wordpress-category-icon.html">2008年, 十月 9日</a>, <a href='http://zeuscn.net/' rel='external nofollow' class='url'>zEUS.</a> writes: 哈哈，前2天我就是在你那边找到的 tor 下载地址呢～
无界我也有用，不过我这人怕麻烦，懒得翻墙...</li><li><a href="http://zeuscn.net/archives/2008/09/10/wordpress-category-icon.html">2008年, 十二月 1日</a>, <a href='http://51blog.co.cc/2008/add-category-icon-for-template.html' rel='external nofollow' class='url'>我要博客 &raquo; 内容索引 &raquo; 为WordPress主题添加分类图标 - 网络 知识 分享 生活</a> writes: [...] 但搞了半天没有成功，在网上搜了一下，发现是用的这样的方法，原文请见：Wordpress 技巧—显示分类图片，代码如下： [...]</li><li><a href="http://zeuscn.net/archives/2008/09/10/wordpress-category-icon.html">2008年, 十二月 19日</a>, <a href='http://www.yanjiecao.com' rel='external nofollow' class='url'>沿阶草</a> writes: 还可以尝试为这篇文章的div创建一个class名字，然后CSS加入背景不是更好么？</li><li><a href="http://zeuscn.net/archives/2008/09/10/wordpress-category-icon.html">2008年, 十二月 25日</a>, <a href='http://www.lalazhu.com/' rel='external nofollow' class='url'>l啦啦猪娱乐</a> writes: 恩，看起来很不错的样子</li><li><a href="http://zeuscn.net/archives/2008/09/10/wordpress-category-icon.html">2009年, 十月 21日</a>, <a href='http://t9labs.net.ru/wei-wordpress-tianjiafenleitubiao-er/' rel='external nofollow' class='url'>为WordPress添加分类图标(二) &#8211; T9Labs</a> writes: [...] 但搞了半天没有成功，在网上搜了一下，发现是用的这样的方法，原文请见：Wordpress 技巧—显示分类图片，代码如下： &lt;?php foreach((get_the_category()) as $cat) { $catname =$cat-&gt;category_nicename; echo &quot;&lt;a href=/category/&quot;; echo $catname; echo &quot;/&gt;&quot;; echo &quot;&lt;img src=http://yourdomain/wp-content/cat-icons/&quot;; echo $catname; echo &quot;.jpg alt=&quot;$catname category &quot; title=&quot;$catname 分类 &quot; /&gt;&lt;/a&gt;n&quot;; } ?&gt; [...]</li><li><a href="http://zeuscn.net/archives/2008/09/10/wordpress-category-icon.html">2010年, 一月 7日</a>, <a href='http://www.canfree.com' rel='external nofollow' class='url'>左手烟</a> writes: 确实是个好方法，难道这就是传说中的日志缩略图么</li><li><a href="http://zeuscn.net/archives/2008/09/10/wordpress-category-icon.html">2010年, 七月 9日</a>, <a href='http://www.hongbaoshu.net/dev20100709.html' rel='external nofollow' class='url'>开发日志20100709洪宝书 | 洪宝书</a> writes: [...] WordPress 技巧-显示分类图片 [...]</li><li><a href="http://zeuscn.net/archives/2008/09/10/wordpress-category-icon.html">2011年, 三月 11日</a>, <a href='http://www.fouhe.com' rel='external nofollow' class='url'>否何</a> writes: 不错哦，我来试试，体验一下。</li></ul><hr /><p>本文地址：<a href="http://zeuscn.net/archives/2008/09/10/wordpress-category-icon.html">http://zeuscn.net/archives/2008/09/10/wordpress-category-icon.html</a>，转载原创文章请注明 <a href="http://zeuscn.net/">zEUScn.NET</a> ‖
      您可以直接 <a href="http://zeuscn.net/archives/2008/09/10/wordpress-category-icon.html#comments"title="to the comments">发布评论</a>
      </p>
    <p>Copyright©<a href="%%blogurl%%">zEUScn.NET</a>.Some rights reserved.</p>
(Digital Fingerprint:<br /> 05538bd2e0492fe803256b5788cfa6fd)
	<ul class="st-related-posts">
	<li><a href="http://zeuscn.net/archives/2009/06/02/d-z-theme-post-type.html" title="剔除 D&#038;Z Theme 主题“热评日志”列表中的页面 (2009年, 六月 2日)">剔除 D&#038;Z Theme 主题“热评日志”列表中的页面</a> (88)</li>
	<li><a href="http://zeuscn.net/archives/2008/08/18/diary-2.html" title="八月十八日 星期一 晴 (2008年, 八月 18日)">八月十八日 星期一 晴</a> (111)</li>
	<li><a href="http://zeuscn.net/archives/2008/02/27/ipple-utral-beta.html" title="ipple utral beta 上线试运行 (2008年, 二月 27日)">ipple utral beta 上线试运行</a> (23)</li>
	<li><a href="http://zeuscn.net/archives/2009/06/16/1st-trade-of-09-wordpress-tshirt.html" title="09’夏季 WordPress 文化衫第一批团购结束 (2009年, 六月 16日)">09’夏季 WordPress 文化衫第一批团购结束</a> (92)</li>
	<li><a href="http://zeuscn.net/archives/2008/07/11/wordpress-theme-diablo-iii.html" title="敬请期待七月主题—Diablo III (2008年, 七月 11日)">敬请期待七月主题—Diablo III</a> (141)</li>
	<li><a href="http://zeuscn.net/archives/2007/07/05/sthaboutzeusblog.html" title="关于本站的一些说明 (2007年, 七月 5日)">关于本站的一些说明</a> (13)</li>
	<li><a href="http://zeuscn.net/archives/2007/04/03/fh-freedom-blue.html" title="wordpress模板 FH Freedom blue 0.2 (2007年, 四月 3日)">wordpress模板 FH Freedom blue 0.2</a> (10)</li>
	<li><a href="http://zeuscn.net/archives/2008/11/26/javascript-drop-down-menu-for-dz-theme.html" title="给 D&#038;Z Theme 增加一个额外的悬浮菜单 (2008年, 十一月 26日)">给 D&#038;Z Theme 增加一个额外的悬浮菜单</a> (26)</li>
	<li><a href="http://zeuscn.net/archives/2011/07/23/flv-player-and-bitcomet-flv-converter.html" title="WordPress flv 视频播放插件：flv-player 的安装使用及下载 附带 BitComet FLV 转换器下载 (2011年, 七月 23日)">WordPress flv 视频播放插件：flv-player 的安装使用及下载 附带 BitComet FLV 转换器下载</a> (102)</li>
	<li><a href="http://zeuscn.net/archives/2007/10/11/css-image-cool-effect.html" title="介绍一个 CSS 图片特效 (2007年, 十月 11日)">介绍一个 CSS 图片特效</a> (85)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://zeuscn.net/archives/2008/09/10/wordpress-category-icon.html/feed</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
	</channel>
</rss>

