Posted in: 张贴在:
4,864 views 4864的意见
Please note: This page was originally written in English.请注意:此页中,原本以英文书写。
The original post can be viewed原来的文章可以看 here这里 . 。
Please note: This page was originally written in English.
The text has been translated using an online service such as Google or Babelfish.
The original post can be viewed here.
I’m going to show you how to add some simple PHP code to your Wordpress template and make linked images appear instead of text for your categories in posts.我要告诉您如何添加一些简单的PHP代码到您的WordPress模板,使联系图片显示的文字,而是为您的类别的职位。 All you need to know is simple PHP, some basic HTML, and how to make your own graphics.所有您需要知道的是简单的PHP中,一些基本的HTML ,以及如何使自己的图形。
**UPDATE** May 2008 **更新** 2008年5月
As the last comment at the end of this page shows there is now a作为最后的评论在本月底页显示现在是一 Category Icons Wordpress Plugin 类别图标wordpress插件 you can download to install to manage your category icons right in your dashboard.您也可以下载安装到管理您的类别图标的权利,在您的控制台。 If you prefer to hack your theme, the code below will work just fine!如果您喜欢哈克您的主题,下面的代码将工作只是罚款! The cool thing about the plugin is that they give you ways to do one or multiple category icons, but also a methods for putting icons with your categories in the side bar as well!冷静的事,关于插件的是,他们给你如何做一个或多个类别的图标,但也是一个方法,把图标与您的类别在一边,大律师公会,以及! I’m always very grateful when a good plugin come along!我一直非常感激,当一个很好的插件来! Now back to the original post…现在回到原来的职位…
Have you ever wanted to hack Wordpress and just make it do something you always wanted it to do?您是否曾经想入侵的WordPress和公正,使做点事你总是希望它做什么呢? I think of things I want it to do all the time but don’t always have the hours to devote to finding the answer.我认为对的事情,我想它做的所有的时间,但并不总是有时间投入到寻找答案。 I’ve searched for PHP code snippets for Wordpress and tutorials and how-to articles as well and haven’t seen much that really helped me.我已经搜查PHP代码的片段内容,在WordPress和教程和如何使用的文章,以及和没有看过太多真的帮了我。 Until today - when I read直到今天-当我看到 the tutorial page at WPDesigner today补习页wpdesigner今天 . 。 I didn’t get exactly the code I needed, but pretty close.我并没有得到完全的代码我需要,但相当接近。 I just needed to hack it a bit to get it to do what I wanted.我只是需要开刀,这一点得到它做什么我想。
First, this Wordpress tutorial hack assumes a few things.第一,这在WordPress补习哈克上台几件事。
- You’ve modified your Wordpress template code before您修改了您的WordPress模板代码之前,
- You can modify simple PHP您可以修改简单的PHP
- You can write simple HTML你可以写简单的HTML
- You can make your own graphics你可以作出自己的图形
First things first - here’s the code:第一件事第一-这里的代码如下:
<h3><b>Posted in:</b></h3> <?php foreach((get_the_category()) as $cat) { $catname =$cat->category_nicename; echo "<a href\"/category/"; echo $catname; echo "/\">"; echo "<img src\"/wp-content/cat-icons/"; echo $catname; echo ".png\" alt=\"$catname category image\" border=\"0\" /></a>\n"; } ?><br /> <h3>快来的<b>张贴在: < / b > < / H3的> < ? PHP的foreach ( ( get_the_category ( ) )作为元,猫) ( $ catname = $猫“ -> c ategory_nicename;回声” <一h ref\ “ /类别/ “ ;回声元catname ;回声” / \ “ > ” ;回声“ <国际管理集团钢骨混凝土\ ” / wp-content/cat-icons / “ ;回声元catname ;回声” 。巴纽\ “按Alt = \ ” $ catname类形象\ “边境= \ ”零\ “ / > < /一> \ n ” ; ) ? > <br /> I hacked this code from this tutorial page on WPdesigner i砍死此代码从本教程的网页wpdesigner . 。 The code they had was only good to display one category per post.该守则,他们只是很好的展示一类%后。 I hacked it because my blogs all have posts assigned to multiple categories. i砍死的,因为我的Blog都有职位分配给多个类别。 Also, I wanted the images to all be linked so people can just click them and go right to that category page.此外,我希望所有的图像联系起来,以便人们可以,只要按一下他们走的权利,这一类的网页。 Let’s look at the pieces of this code you might need to modify.让我们看看在这件代码,您可能需要修改。
In line 1, you might want change “Posted in:” to alternate text like “Filed under:”, etc.在1号线,您可能会想要改变“张贴在: ”以替代文字一样, “提起下: ”等。
In line 5, if your permalink structure is different than the default, you may need to change /category/ to what you are using.在5号线,如果您的永久结构是不同的,比默认情况下,您可能需要变更/类别/什么您所使用的。
In line 8 change /wp-content/cat-icons/ to wherever you will be storing your category icons in your site.在8号线变更/ wp-content/cat-icons /您在何处,将储存您的图象类别,在您的网站。
In line 10, if you are using gif’s or jpg’s change .png to your graphic file format.在第10行,如果您正在使用的GIF的或JPG的改变。巴纽到您的图形文件格式。
Now all you have to do is create one image for every category you have an place them in the folder you just created on the server.现在,所有您需要做的就是建立一个形象,每一个类你有一个地方,他们在该文件夹中您刚刚创建的服务器上。 Make sure that the graphics are named exactly as your categories, and if your categories have multiple words just add a hyphen in between each word.作出肯定的是,图形命名,正是由于您的类别,如果您的类别有多个的话只是添加一个连字符之间的每个字。 That’s it!这样就大功告成了! All you have to decide now is where you want these category icons to appear, before or after your post - and add them into the appropriate place.所有你必须决定,现在是您想要这些类别的图标出现,之前或之后,您的帖子-并将它们添加到适当的地方。 I placed mine just after the title of the post on my single post pages - as you can see at the top of the post on this page. i放在煤矿刚刚结束的标题后对我的单后的页面-你可以看到在顶部的职位在此页中。 You can hack this category icon code a hundred other ways to do what you want.您可以哈克这一类的图标代码100其他的方法可以做到你想要的。 I think in the future I’m going to use it to replace the text category links in my sidebar.我认为在未来的,我会用它来取代文本分类链接在我的工具栏。 The only caveat to this (and the code hack above) would be the fact that if you don’t have an image a text link will display (in FF, or broken image in IE).唯一的警告,这(和代码哈克以上)将成为事实,就是如果你没有一个形象的文本链接将显示(在FF ,或破碎的形象,在IE ) 。 So - if you create new categories in the future, make sure you create a new image for each.所以-如果您创建新的类别在未来的日子,请务必建立一个新的形象,为每个。
My Blogging Mistake for this post is that I didn’t decide to customize and hack my Wordpress Theme before now to create my own layout.我的博客错误,这个职位是,我并没有决定要自定义和哈克我的WordPress的主题之前,现在创建自己的布局。 Do you have a question or a new way to hack up this wordpress category icon PHP code?你有问题或一条新的途径哈克这在WordPress类图标的PHP代码? Comments and post it now!评论和邮政现在!


















January 8th, 2008 at 10:40 am 2008年1月8日上午10时40分
This was very easy to do - thanks for the code and the tip!这是很容易的事-感谢守则及提示!
The Smorgasbord’s last blog post.. 该smorgasbord的最后的博客帖子.. Convert Vinyl Records to MP3 转换乙烯基纪录的MP3
January 24th, 2008 at 9:47 pm 2008年1月24日在下午9点47分
[...] Imágenes para las categorías [...] [ … … ] ,图片搜索第拉斯维加斯类别[ … … ]
January 25th, 2008 at 4:49 am 2008年1月25日在上午04时49分
25 неотстойных хаков для WordPress 25 неотстойных хаков для的WordPress
Динамическое слайдшоу в шапке — позволяет крутить картинки в шапке вашего блока, придает динамику; демоверсия. динамическое слайдшоу в шапке -п озволяетк рутитьк артинкив ш апкев ашегоб лока, п ридаетд инамику; д емоверсия。
Пузырь комментариев — гр… пузырь комментариев -г р…
January 25th, 2008 at 8:52 am 2008年1月25日在上午8时52分
[...] Imagens para categorias. [ … … ]图片第类别。 Adiciona imagens para cada categoria do seu blog e são mostradas no post se você preferir. adiciona图片第在无法种类做请输入您的博客e圣保罗mostradas没有邮政本身左侧preferir 。 [...] [ … … ]
January 27th, 2008 at 2:48 pm 2008年1月27日在下午2时48分
[...] Imagens para categorias. [ … … ]图片第类别。 Adiciona imagens para cada categoria do seu blog e são mostradas no post se você preferir. adiciona图片第在无法种类做请输入您的博客e圣保罗mostradas没有邮政本身左侧preferir 。 [...] [ … … ]
March 9th, 2008 at 12:13 am 2008年3月9日在上午12时13分
[...] Show Category Images (Source: [...] [ … … ]显示类图像(资料来源: [ … … ]
March 13th, 2008 at 12:40 am 2008年3月13日在上午12时40分
[...] Show Category Images (Source: [...] [ … … ]显示类图像(资料来源: [ … … ]
March 13th, 2008 at 1:51 am 2008年3月13日在上午01时51分
[...] Show Category Images (Source: [...] [ … … ]显示类图像(资料来源: [ … … ]
March 16th, 2008 at 6:43 pm 2008年3月16日在下午6时43分
[...] 10)Show Category Images- How to add some simple PHP code to your WordPress template and make linked images appear instead of text for your categories in posts. [ … … ] 10 )显示类图像-如何添加一些简单的P HP代码到您的W ordPress模板,使联系图片显示的文字,而是为您的类别的职位。 [...] [ … … ]
March 17th, 2008 at 9:40 am 2008年3月17日在上午09时40分
Great hack!伟大的黑客! thanks谢谢
March 23rd, 2008 at 7:40 am 2008年3月23日在上午07时40分
[...] Show Category Images (Source: [...] [ … … ]显示类图像(资料来源: [ … … ]
April 12th, 2008 at 12:18 pm 2008年4月12日在下午12时18分
[...] sticky”- When we need to have certain articles ’stay at the top’ longer than others. [ … … ]粘“ -当我们需要有一定的文章'留在顶端'的时间比别人。 10)Show Category Images- How to add some simple PHP code to your WordPress template and make linked images appear instead [...] 10 )显示类图像-如何添加一些简单的P HP代码到您的W ordPress模板,使联系的图片出现,而是[ … … ]
April 15th, 2008 at 2:02 am 2008年4月15日在上午02时02分
Hi嗨
here is a plugin that do the job :这里是一个插件这样的工作:
Category Icons Plugin类别图标插件 . 。
April 19th, 2008 at 10:47 am 2008年4月19日在上午10时47分
That is a very nice Hack!这是一个很好的黑客! I realize there is a plugin now, but I think I am going to just edit this in one of my projects.我知道有一个插件现在,但我觉得我要刚才编辑这在我的一个项目。 Thanks for writing it down!感谢写作!
April 21st, 2008 at 9:02 am 2008年4月21日在上午09时02分
[...] : JTPRATT’s Blogging Mistakes ( here & here ), Performancing Helping Bloggers [...] [ … … ] : jtpratt的博客的错误(在这里&这里) , performancing帮助博客[ … … ]
April 27th, 2008 at 9:50 am 2008年4月27日在上午09时50分
[...] 84. [ … … ] 84 。 No More CSS Hacks.没有更多的CSS技巧。 85. 85 。 Create a Dynamic Sticky.创建动态棘手。 86. 86 。 Styling Individual Posts Using the_ID.造型个别职位,使用the_id 。 87. 87 。 Show Category Images.显示类的图片。 88. 88 。 Separate WordPress Comments and Trackbacks.单独的WordPress的评论和trackbacks 。 89. 89 。 Customize your WordPress Login.自定义您的WordPress登录。 90. 90 。 Date Image [...]日期形象[ … … ]
May 16th, 2008 at 2:26 am 2008年5月16日在上午02时26分
[...] 84. [ … … ] 84 。 No More CSS Hacks 85.没有更多的CSS技巧85 。 Create a Dynamic Sticky 86.创建动态粘86 。 Styling Individual Posts Using the_ID 87.造型个别职位,使用the_id 87 。 Show Category Images 88.显示类图像88 。 Separate WordPress Comments and Trackbacks 89.单独的WordPress的评论和trackbacks 89 。 Customize your WordPress Login 90.自定义您的WordPress登录90 。 Date Image [...]日期形象[ … … ]
June 6th, 2008 at 4:38 am 2008年6月6日在上午04时38分
[...] Hacks84. [ … … ] hacks84 。 No More CSS Hacks85.没有更多的CSS hacks85 。 Create a Dynamic Sticky86.创建动态sticky86 。 Styling Individual Posts Using the_ID87.造型个别职位,使用the_id87 。 Show Category Images88.显示类images88 。 Separate WordPress Comments and Trackbacks89.单独的WordPress的意见和trackbacks89 。 Customize your WordPress Login90.自定义您的WordPress login90 。 Date Image [...]日期形象[ … … ]