幾個 WordPress 小技巧

照理說 codex.wordpress.org 將資料整理得這麼齊全方便,許多關於 WordPress 的相關問題,只要稍事搜尋,應該便可以迎刃而解,不過身邊一些朋友或是囿於語言上的限制,或是缺乏一些資料庫以及動態頁面的觀念,要找資料,還是不知如何找起。比方說最近有人就問我這樣的問題:怎樣在頁面的某個位置上,不要從第一篇開始列出文章,而是要自訂只列出第二篇到第四篇;或,第一篇列出全文,而從第二篇到第四篇,只列出標題…等等。

WordPress 是透過 PHP 以及 MySQL 語法,從資料庫中讀取文章內容,所以要限制只抓從某一篇到某一篇的範圍,就是透過 offset(偏移)以及 limit (限制)兩個語法。而用 WP 的術語來說,在index.php 等模板檔案中,用來顯示文章的範圍,叫做 loop,而在首頁、日期彙整、單篇彙整等不同的狀況下,在 loop 中會列出數量、範圍不同的文章,也就是,在程式執行到 loop 之前,其他部份的程式已經幫你設好了資料庫的選擇(select)範圍,然後將這些文章的相關資料(內文、標題等),塞到 loop 當中,再從 loop 中設定的語法,顯示文章。

Continue reading

四月一日流水帳

記一下這一兩天的幾筆流水帳。

首先要說的是,前兩天傳出,有人發現 WordPress 的主要開發者 Matthew Mullenweg,企圖因為 wordpress.org 擁有相當高的 Google PageRank(原因是目前所有以 WP 架設的系統,頁面上都會有一個連到 wordpress.org 的連結),因此在網站上放置了許多與軟體開發專案無關的頁面,頁面中又充滿許多具有 Google Adsense 商業價值的關鍵字,以此影響搜尋引擎的搜尋結果,增加廣告收入;在台灣的網誌當中,gslin的這篇〈WordPress Website 的 Spam 問題〉描述得相當詳細,比較完整的發展可以參見 Waxy.org 的 WordPress Website’s Search Engine Spam

而說真的,今天全天下人都在 spam Google 搜尋引擎,君不見到處都是所謂從事「搜尋引擎行銷」的什麼專業行銷網站?Matt 的行為卻被以更高的標準看待,而 WP 本身擁有這麼高的 PageRank ,也是因為經營這個自由軟體計畫大約已經兩年的成果,相較之下比起許多來自中國的 spammer 到處刪除其他 wiki 站台上的內容,然後說什麼:「你的站做得實在很好,想和你交換以下友情連結」之類的,WordPress 這麼做似乎也更為正當。

Continue reading

將圖書館書目資料轉換成引用書目格式轉貼到 WordPress 的 bookmarklet

這個東西是從前面提到的將全國圖書書目資訊網轉換成論文參考書目格式的書籤小工具繼續發展的,簡單來說,這個工具可以讓你在某個圖書館的書目查詢系統,查到某一筆資料的時候,按一下某個書籤,就可以將這筆書目轉成中文論文的引用書目格式,然後透過 WordPress 原本提供的快速發表 bookmarklet 頁面,將這筆資料貼到 WordPress裡頭。然後,你可以使用 WordPress 所提供的分類功能,整理這些書目。

這個工具目前放在中文 WordPress 專案的下載頁面上,把 bookmarklets.tar.gz 抓下來解開之後,會出現一個 bookmarklets 目錄,然後把這個目錄丟到 /wp-contnets/ 底下即可,自然,您需要先安裝一套 WordPress 。要使用的話,就使用瀏覽器開啟 http://example.com/wp-contnets/bookmarklets/,在這個頁面上,您可以看到一個書籤小程式的鍊結,把這個鍊結加入書籤。

Continue reading

A prototype of the WordPress Technorati-links plugin

I wrote a WordPress plugin last night. It is now running on my own weblog though it is just a prototype now. The function of this plugin is to retrieve the information about how many links is linked to your weblog and your post entries from Technorati.

I consider that Technorati supports two main on-line services, one is it can sort blog entries from any other weblogs, photos from flickr, links from del.icio.us in the same category or tag, while another is you can find the posts from other sites which is linked to your site. Keith McDuffee is now working on a WordPress plugin called TechnoTag, it can let you add tags to your posts as you like, it is used for the first main service of Techorati.

Then, you can see there are many sites would like to use Techorati to display the comments from other weblogs, for instance, there is a hyper-link called “blog’s comments” in every post of BoingBoing, and you can know about how many links are linked to your WordPress 1.5 blog from the dashboard page in the user interface for the administrators. However, there is still no plugin to let you know how many links are linked to your every single post, and this plugin is required, I think.

You can download the plugin here. Save it as a text file with file extension as “.php” and upload to “wp-content/plugins” directory in the directory that you installed WordPress. Visit the “Pugins” tab and unable it. Then, create a cache path such as “wp-content/technorati”, make it writable, and please edit your plugin file and change the value of $cache_path into your exact path. Then, edit your php files located in your WordPress theme directory, and add <?php techolink(get_permalink(), "", "") ?> into the loop. If there are no links linked to the permanent links of your posts, it displays “n links from n sources” , and it display nothing while there is not any link.

This plugin caches the informations from Technorati, I have not finished the part of deleting the cache files to update the informations while Technorati is updated. You need to delete these files by your self in a period whiling using the current version. I may finish it somehow later, and it is welcomed to continue my work if you are interested.

WordPress 1.5 在 wp-rss2.php 的 bug

最近時間實在不多,所以說真的,實在很不想花時間處理像這樣的事情。而才剛升級到 WordPress 1.5 ,居然就發現了一個嚴重的缺陷,那就是,如果你在 WordPress 1.5 上套用了英文語系以外的語系檔案(例如中文化),那麼 RSS2 的feed就會爛掉,原因是 WP 1.5 會把 RSS2 當中的日期語法,如月份、星期幾等,也一併換成語系檔案中的字串,而造成各種 RSS 閱讀軟體無法閱讀。

解決的方法是要改一下 wp-rss2.php 這個檔案,找一下第 36 行,把:

<pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_the_time('Y-m-d H:i:s')); ?></pubDate>

改成

<pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_the_time('Y-m-d H:i:s'), 0); ?></pubDate>

相關討論可以參見:

RSS2 feed does not validate when using translation mo file
wp-rss2.php broken after localization

升級 WordPress 1.5

WordPress 1.5版上週正式釋出,這不算是什麼新聞,包括許多在台灣使用WordPress的使用者都已經升級到了新版本,許多甚至在還沒有釋出前就已經更換成開發當中的版本;所以,這個新版本有什麼新功能也就暫且不提,相信在別的地方應該都提過了。

另外,在1.5版還在開發的過程中,piaip就已經製作、完成了正體中文語系檔案zh_TW.po檔案,因此在1.5版釋出的同時,正體中文版的使用者也便立刻已經有了正體中文版本可以使用(下載),因為這陣子我幾乎都把心思放在別的事情上(例如什麼藏文輸入之類的),正體中文的 WP 1.5 版的相關工作,幾乎都是 piaip 獨立完成的。不過,我剛剛看了一下中文WordPress專案的svn repository裡頭好像缺漏了一些檔案的樣子,似乎是在1.5版釋出的前幾天,官方將一些檔案又拆成了獨立的檔案,而忘記順便 svn add 這些檔案,等下應該再來檢查一下。

Continue reading