這個外掛並未在最新的 3 個 WordPress 主要版本上進行測試。開發者可能不再對這個外掛進行維護或提供技術支援,並可能會與更新版本的 WordPress 產生使用上的相容性問題。

Random Post on Refresh

外掛說明

Random Post on Refresh 外掛讓使用者在頁面載入時隨機顯示不同文章的內容。

外掛的使用方式非常簡單:

  1. 安裝外掛。
  2. 啟用外掛。
  3. 在頁面或文章要顯示隨機文章內容的地方,插入 [random_post_on_refresh] 短代碼,之後載入這個有短代碼的頁面便會顯示隨機文章內容。
  4. 儲存編輯內容。

外掛特色

  • 可用於自訂內容類型。
  • 沒有外掛設定頁面,透過外掛提供的短代碼便能在網站上顯示隨機文章內容。
  • 乾淨、良好撰寫習慣且不會造成網站遲滯的程式碼。

安裝方式

先決條件

如果網站主機不符合安裝必要條件,強烈建議升級網站的 WordPress 版本,或將網站遷移至支援較新版本 PHP 的主機環境。

  • 需要 WordPress 3.2 或更新版本
  • 需要 PHP 5 或更新版本 (WordPress 3.2 僅能執行於 PHP 5.2.4 或更新版本)

自動安裝

  1. 在 WordPress 管理後台中,前往 [外掛] 頁面,然後點擊 [安裝外掛]。
  2. 在搜尋框中,輸入 Random Post on Refresh 並按下 Enter 鍵,這個外掛應該會是第一筆或唯一的搜尋結果。
  3. 點擊 [安裝]。
  4. 安裝完畢後,點擊 [啟用]。

手動安裝

  1. 下載外掛安裝套件的 ZIP 壓縮檔。
  2. 將解壓縮得到的 random-post-on-refresh 資料夾上傳至網站的 /wp-content/plugins/ 目錄。
  3. 在 [外掛] 頁面中找到這個外掛,然後點擊 [啟用]。

常見問題集

[random_post_on_refresh] 短代碼提供多個屬性,讓使用者能更細部控制隨機文章內容的顯示結果:

  • author:如果只需要顯示一位或少數幾位作者的隨機文章,請使用作者 ID 或以逗號分隔多個作者 ID。範例:[random_post_on_refresh author="1, 11, 14"]

  • ids:如果只需要顯示指定文章為隨機文章,請使用文章 ID 或以逗號分隔多個文章 ID。範例:[random_post_on_refresh ids="19, 87, 113, 997"]

  • image_required:這項屬性僅會在 show 屬性包含 image 時生效。這個屬性的預設值為 true,並會讓 WordPress 篩選掉沒有圖片的文章。如果這個屬性設定為 false,那無論文章是否有圖片都會加以顯示。範例:[random_post_on_refresh show="title, image" image_required="false"]

  • not:如果只需要顯示排除指定文章的隨機文章,請使用文章 ID 或以逗號分隔多個文章 ID。範例:[random_post_on_refresh not="3, 456, 876"]

  • post_type:如果只需要顯示指定內容類型的隨機文章,請使用指定內容類型的代稱。這個屬性的預設值為 post。範例:[random_post_on_refresh post_type="page"]

  • search:將指定搜尋關鍵字傳回的文章顯示為隨機文章。範例:[random_post_on_refresh search="relativity"]

  • taxonomy:用於顯示指定分類法的隨機文章,必須搭配 terms 屬性使用。範例:[random_post_on_refresh taxonomy="post_tag" terms="2,4"]

  • terms:用於顯示指定分類法詞彙的隨機文章,請使用分類法詞彙 ID 或以逗號分隔多個分類法詞彙 ID,且必須搭配 taxonomy 屬性。使用範例:[random_post_on_refresh taxonomy="post_tag" terms="2,4"]

  • class:將 HTML div 標籤中包含指定的類別名稱的內容顯示為隨機文章。範例:[random_post_on_refresh class="my-custom-class"]

  • size:將包含指定註冊尺寸圖片的內容顯示為隨機文章。這是選用屬性,僅適用於包含圖片的內容。範例:[random_post_on_refresh size="thumbnail"]

  • show:僅顯示隨機文章的指定內容元素,請使用逗號或分隔號 | 分隔多個內容元素。有效的屬性值為 title、image、excerpt 及 content,預設值為 title, image, excerpt。範例:[random_post_on_refresh show="title, image"]

請銘記於心,以上短代碼屬性均可依需求合併使用。範例:[random_post_on_refresh author="19" size="full" not="2310"]。此外,外掛提供的短代碼也可以使用於核心程式內建的 [文字] 小工具。

使用者評論

2021 年 3 月 11 日 1 則留言
Feels light weight and does exactly what it says it does.
2020 年 9 月 17 日 1 則留言
Works like a charm, does exactly what I wanted it to do! Thanks Micah!
2020 年 5 月 29 日 1 則留言
Does exactly what it says it does. Be sure to suppress caching on the pages that you use it.
閱讀全部 5 則使用者評論

參與者及開發者

以下人員參與了開源軟體〈Random Post on Refresh〉的開發相關工作。

參與者

〈Random Post on Refresh〉外掛目前已有 1 個本地化語言版本。 感謝全部譯者為這個外掛做出的貢獻。

將〈Random Post on Refresh〉外掛本地化為台灣繁體中文版

對開發相關資訊感興趣?

任何人均可瀏覽程式碼、查看 SVN 存放庫,或透過 RSS 訂閱開發記錄

變更記錄

1.2

  • Added a shortcode attribute to allow posts without images to be shown when the show attribute contains image.
  • Bug fix for certain strings not being translatable.

1.1.1

  • Fixed bug where post excerpts were being generated incorrectly.

1.1

  • Ensure code meets coding standards.
  • Don’t allow the current post to be selected as the random post.
  • Always return the last 100 matching items and select the random post from one of those.
  • Tested in WordPress 5.0

1.0

  • Tested in WordPress version 4.9.2