Posted in: 張貼在:
4,894 views 4894的意見
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 [...]日期形象[ … … ]