
內容簡介
此外掛提供模板標籤,允許您檢索指定目錄中隨機選擇的文件名稱、路徑(相對或絕對)、URL,或完整標記的鏈接。
函數的參數允許您根據給定的文件擴展名限制可以隨機選擇的文件。您還可以明確指定不應隨機選擇的文件。這個功能可用於顯示隨機圖像/標識或將來自隨機文件的文本包含在您的網站上(寫作摘要,多行引用等)。其他想法:隨機廣告,隨機CSS文件,隨機主題模板選擇。可以在“the loop”內外運行。
注意事項:
如果要實際顯示隨機文件的名稱,請確保“echo”結果。
除非通過“$extensions”參數將文件搜索限制為僅包括特定擴展名,否則指定的“$dir”中的所有文件都將被考慮為隨機選擇。
可以在“the loop”內外運行。
鏈接:插件主頁 | 插件目錄頁面 | GitHub| 作者主頁
模板標籤
此外掛提供了兩個可選的模板標籤,可用於您的主題模板。
函數
<?php function c2c_random_file( $dir, $extensions = '', $reftype = 'relative', $exclusions = array() ) ?>
此函數從指定目錄中檢索隨機文件的名稱,並根據$reftype值返回文件相關信息。
<?php function c2c_random_files( $number, $dir, $extensions = '', $reftype = 'relative', $exclusions = array() ) ?>
此函數從指定目錄中檢索指定數量的隨機選擇文件的名稱、路徑或鏈接。除了$number參數,其餘參數都會被傳遞到c2c_random_file()。
參數
$number(僅限於c2c_random_files())
要從指定目錄中選擇的隨機文件數量。如果指定目錄中存在少數文件,則將返回目錄中的所有文件(但會以隨機順序列出)。
$dir
要檢索隨機文件的目錄。該目錄必須存在於您的WordPress安裝的文件夾結構級別或以下。 (即,如果您的站點在伺服器上安裝在/usr/local/htdocs/example.com/www/journal/,則您指定的隨機文件目錄將假定其為基礎...因此,對於值'randomfiles',將假定實際上是:/usr/local/htdocs/example.com/www/journal/randomfiles/)
$extensions
可選參數。以空格分隔的擴展名列表(不區分大小寫),即'jpg gif png jpeg'。
$reftype
可選參數。可以是以下之一:'相對'(默認值)、'絕對'、'url'、'filename'、'hyperlink'。有關詳細信息和範例,請參見示例部分。
$exclusions
可選參數。如果指定,必須是要從考慮中排除的文件名數組。
外掛標籤
開發者團隊
📦 歷史版本下載
原文外掛簡介
This plugin provides template tags that allow you to retrieve the name, path (relative or absolute), url, or fully marked-up link to a randomly chosen file or files in a specified directory.
Arguments to the functions permit you to limit what file(s) can be randomly selected based on a given set of file extensions. You can also explicitly specify files that should not be randomly selected.
This functionality can be useful for displaying random images/logos or including text from random files onto your site (writing excerpts, multi-line quotes, etc). Other ideas: random ads, random CSS files, random theme template selection.
Notes:
If you want to actually display the name of the random file, be sure to ‘echo’ the results:
Unless you limit the file search to only include a particular extension (via $extensions argument), all files in the specified $dir will be under consideration for random selection
Can be run inside or outside of “the loop”
Links: Plugin Homepage | Plugin Directory Page | GitHub | Author Homepage
Developer Documentation
Developer documentation can be found in DEVELOPER-DOCS.md. That documentation covers the template tags and hooks provided by the plugin.
As an overview, these are the template tags provided by the plugin:
c2c_random_file() : Retrieves the name of a random file from a specified directory and returns information based on the file.
c2c_random_files() : Retrieves the name, path, or link to a specified number of randomly chosen files in a specified directory.
These are the hooks provided by the plugin:
c2c_random_file : Filter to safely invoke c2c_random_file() in such a way that if the plugin were deactivated or deleted, then your calls to the function won’t cause errors in your site.
c2c_random_files : Filter to safely invoke c2c_random_files() in such a way that if the plugin were deactivated or deleted, then your calls to the function won’t cause errors in your site.
