[WordPress] 外掛分享: Random Posts for Query Loop Block

首頁外掛目錄 › Random Posts for Query Loop Block
全新外掛
安裝啟用
尚無評分
69 天前
最後更新
問題解決
WordPress 6.0+ PHP 7.4+ v1.0.5 上架:2026-01-06

內容簡介

總結:
WordPress 中的查詢循環塊不包含在側邊欄 UI 中有一個“隨機”排序選項。
然而,WordPress 核心支持 WP_Query 中的 orderby = rand。
問題:
在查詢循環塊中使用“orderBy”:”rand" 可能會使網站編輯預覽失敗,因為 rand 不包含在 REST API schema 中的文章中。
這款外掛通過擴展 REST API orderby 枚舉來解決這個問題,進而使編輯器識別 "rand" 的有效性。

<ul>
<li>這款外掛的功能:
<ul>
<li>將 "rand" 添加到 REST API 中文章和頁面的 orderby 枚舉值中。</li>
<li>允許查詢循環塊安全使用 "orderBy":”rand"。</li>
<li>防止網站編輯器中的 JSON 錯誤和預覽失效。</li>
<li>使“隨機文章”布局在編輯器和前端都可以可靠運作。</li>
</ul>
</li>
<li>這款外掛不會:
<ul>
<li>在查詢循環 UI 下拉菜單中添加“隨機”選項。</li>
<li>(該 UI 定義在 Gutenberg 的 JavaScript 中。)</li>
<li>仍需使用代碼編輯器手動設置 "orderBy":”rand"。</li>
</ul>
</li>
</ul>

問與答:
1. 這款外掛的作用是什麼?
- 將 "rand" 添加到 REST API 中文章和頁面的 orderby 枚舉值。
- 允許查詢循環塊安全使用 "orderBy":”rand"。
- 防止網站編輯器中的 JSON 錯誤和預覽失效。
- 使“隨機文章”布局在編輯器和前端都可以可靠運作。

2. 這款外掛不會做什麼?
- 在查詢循環 UI 下拉菜單中添加“隨機”選項。
- 仍需使用代碼編輯器手動設置 "orderBy":”rand"。

3. 如果想要讓首頁、部落格、引言網站、推薦區每次頁面加載時顯示不同的文章,應該怎麼做?
- 安裝這款外掛
- 開啟模板
- 切換到代碼編輯器
- 設置 "orderBy":”rand"。

外掛標籤

開發者團隊

⬇ 下載最新版 (v1.0.5) 或搜尋安裝

① 下載 ZIP → 後台「外掛 › 安裝外掛 › 上傳外掛」
② 後台搜尋「Random Posts for Query Loop Block」→ 直接安裝(推薦)
📦 歷史版本下載

原文外掛簡介

The Query Loop block in WordPress does not include a “Random” ordering option in the sidebar UI.
However, WordPress core does support orderby = rand in WP_Query.
The problem:
Using "orderBy": "rand" inside a Query Loop block can cause the Site Editor preview to fail, because rand is not included in the REST API schema for posts.
This plugin fixes that by extending the REST API orderby enum so the editor recognizes "rand" as valid.
✔ What this plugin does

Adds "rand" to the REST API orderby enum for posts and pages.
Allows the Query Loop block to use "orderBy": "rand" safely.
Prevents JSON errors and broken previews in the Site Editor.
Makes “random post” layouts work reliably both in the editor and frontend.

⚠ What this plugin does not do

It does not add a “Random” option to the Query Loop UI dropdown.
(That UI is defined in Gutenberg’s JavaScript.)
You must still set "orderBy": "rand" manually using the Code Editor.

Example use case
Want your homepage, blog, quotes site, testimonials, or featured-section to show
a different post every time the page loads?
Install this plugin → open the template → switch to Code Editor → set "orderBy": "rand".

延伸相關外掛

文章
Filter
Apply Filters
Mastodon