Random File

外掛說明

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 specify 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.

Theses are the hooks provided by the plugin:

  • c2c_random_file : Allows use of an alternative approach 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 : Allows use of an alternative approach 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.

安裝方式

  1. Install via the built-in WordPress plugin installer. Or download and unzip random-file.zip inside the plugins directory for your site (typically wp-content/plugins/)
  2. Activate the plugin through the ‘Plugins’ admin menu in WordPress
  3. Make use of the c2c_random_file() or c2c_random_files() template function in your code or template (see examples below).

常見問題集

Does this plugin do dynamic random rotation within a loaded page (i.e. randomly rotating images within a loaded page)?

No. This plugin only selects a random file when the page is loaded. Once loaded, it does not currently add any dynamic functionality to automatically retrieve another random file on its own.

Does this plugin include unit tests?

Yes.

使用者評論

這個外掛目前沒有任何使用者評論。

參與者及開發者

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

參與者

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

對開發相關資訊感興趣?

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

變更記錄

1.8.12 (2023-05-21)

  • New: Add DEVELOPER-DOCS.md and move hooks documentation into it
  • Change: Note compatibility through WP 6.3+
  • Change: Update copyright date (2023)

1.8.11 (2021-09-18)

  • Change: Note compatibility through WP 5.8+
  • Unit tests:
    • Change: Restructure unit test directories
      • Change: Move phpunit/ into tests/
      • Change: Move phpunit/bin into tests/
    • Change: Remove ‘test-‘ prefix from unit test file
    • Change: In bootstrap, store path to plugin file constant
    • Change: In bootstrap, add backcompat for PHPUnit pre-v6.0

1.8.10 (2021-04-23)

  • Change: Note compatibility through WP 5.7+
  • Change: Update copyright date (2021)

Full changelog is available in CHANGELOG.md.