[WordPress] 外掛分享: Custom Query Shortcode

前言介紹

  • 這款 WordPress 外掛「Custom Query Shortcode」是 2015-09-21 上架。
  • 目前有 40 個安裝啟用數。
  • 上一次更新是 2021-04-10,距離現在已有 1486 天。超過一年沒更新,安裝要確認版本是否可用。以及後續維護問題!
  • 外掛最低要求 WordPress 3.3 以上版本才可以安裝。
  • 有 1 人給過評分。
  • 還沒有人在論壇上發問,可能目前使用數不多,還沒有什麼大問題。

外掛協作開發者

shazdeh | peterhebert |

外掛標籤

post | query | shortcode |

內容簡介

此外掛提供了 [query] 短碼,讓你能夠查詢和輸出任何經過特定屬性篩選的文章。

使用方式

你可以使用 WP_Query 類別所支援的 所有參數來篩選文章;你可以查詢特定的文章類型、分類、標籤、作者等等。

其他支援的參數

除了 WP_Query 的參數外,短碼還支援以下額外參數:

featured:查詢置頂文章,預設並不會包含在查詢範圍中。
thumbnail_size:指定 {THUMBNAIL} 圖片大小,在此你可以使用內建圖片大小或自訂大小。
content_limit:限制 {CONTENT} 變數的字數上限;預設為「0」,表示輸出所有內容。
posts_separator:單獨文章之間的文字分隔符號。
lens:自訂輸出範本;詳見下方描述。
twig_template:使用 Twig 範本引擎的輸出範本;需要使用 Timber 庫。

格式化輸出

你可以在開始的 [query] 與結束的 [/query] 標籤內定義輸出格式。
可使用的關鍵字有:TITLE、CONTENT、AUTHOR、AUTHOR_URL、DATE、THUMBNAIL、CONTENT、COMMENT_COUNT。

以下示範將會顯示相關分類ID為3的最新五篇文章,會包含文章標題和評論計數,並且有一個指向文章的連結:
[query posts_per_page=”5″ cat=”3″]

{TITLE} ({COMMENT_COUNT})

[/query]

網格顯示

藉由「cols」參數,你可以在網格內顯示輸出。
[query posts_per_page=”3″ cols=”3″] {THUMBNAIL}

{TITLE}

{CONTENT} [/query]
將會以數列模式顯示最新三篇文章,採用預設的模板、分為3欄顯示。
此外掛會自動根據「posts_per_page」選項除以「cols」選項,分割為多列的網格。

Lenses (輸出範本)

透過「lens」參數,你可以使用範本客製化查詢結果的顯示。此外掛提供某些基本範本:

ul:一個包含文章標題連結的無序列表。
ul-title-date:和「ul」相同,但同時顯示了發布日期。
article-excerpt:一系列文章,包含標題的連結和節錄文字。
article-excerpt-date:和「article-excerpt」相同,但同時顯示了發布日期。
cards:在頁首顯示文章縮圖、標題連結,並接著節錄文字輸出。

Bootstrap 範本

此外掛提供了預定義的範本/模板,利用 Bootstrap CSS 框架中的 JavaScript 組件。
此功能需要頁面已經載入 Bootstrap 庫,因此此外掛並沒有包含 Bootstrap 庫。
如果你使用的是基於 Bootstrap 的佈景主題,這個功能可用;否則可以使用Bootstrap 插件來實現。

Tabs

這將顯示出一個有分頁的小工具,並顯示最近的 3 篇文章。
[query posts_per_page=”3″ lens=”tabs”]

原文外掛簡介

This plugin gives you [query] shortcode which enables you to query and output any posts filtered by specific attributes.
Usage
You can use all parameters supported by WP_Query class to filter the posts; you can query for specific post types, categories, tags, authors, etc.
Other supported parameters
Aside from WP_Query parameters, the shortcode also supports the following additional parameters:

featured: to query for sticky posts which by default are excluded from the query.
thumbnail_size: to specify the size of the {THUMBNAIL} images. You can use built-in image sizes or custom ones you’ve defined.
content_limit: to limit the number of words of the {CONTENT} var; by default it’s “0” which means it outputs the whole content.
posts_separator: text to display between individual posts.
lens: custom output template – see description below.
twig_template: output template using Twig templating engine – requires the Timber library.

Formatting the output
You can define how you want to format the output inline within an opening [query] and closing [/query] tag.
Available keywords are: TITLE, CONTENT, AUTHOR, AUTHOR_URL, DATE, THUMBNAIL, CONTENT, COMMENT_COUNT.
The following example will display the latest 5 posts from the category with the ID of 3, showing a post title and comment count, with a link to the post:
[query posts_per_page=”5″ cat=”3″]
{TITLE} ({COMMENT_COUNT})
[/query]
Grid display
With the “cols” parameter you can display the output in a grid.
[query posts_per_page=”3″ cols=”3″] {THUMBNAIL}
{TITLE}
{CONTENT} [/query]
will display the latest 3 posts in the defined template, in 3 columns.
The plugin will automatically divide the grid into rows based upon the ‘posts_per_page’ option, divided by the ‘cols’ option.
Lenses (output templates)
With the “lens” parameter you can customize the display of the query results using a template. Some basic lenses/templates are provided:

ul: unordered list of linked post titles.
ul-title-date: same as ‘ul’, but also displays the posted date.
article-excerpt: series of articles, with a header containing the linked post title, and the excerpt.
article-excerpt-date: same as ‘article-excerpt’, but also displays the posted date.
cards: displays the post thumb above the header with linked post title, followed by the excerpt.

Bootstrap lenses
Some pre-defined lenses/templates are provided which use JavaScript Components from the Bootstrap CSS framework.
This feature relies on Bootstrap library to be already loaded on the page, the plugin does not include it.
If you’re using a Bootstrap-based theme, this should work; otherwise you can use the Bootstrap plugin).
Tabs
This will show the latest 3 posts in a tabbed widget.
[query posts_per_page=”3″ lens=”tabs”]
Accordion
This will create an accordion widget of all our posts from the “faq” post type.
[query posts_per_page=”0″ post_type=”faq” lens=”accordion”]
Carousel
This creates a carousel of latest five featured posts:
[query posts_per_page=”5″ featured=”true” lens=”carousel”]
Custom Lenses/templates
You can create your own custom templates and put them into one of these pre-defined folder names within your theme:

‘query-shortcode-templates’
‘partials/query-shortcode-lenses/’
‘html/lenses/’

Or simply specify your own subfolder in the ‘lens’ parameter:
[query lens=”folder/template-name”]
Twig Template Support
Starting with version 0.4, you can use Twig templates for your output. Support for Twig is provided by the Timber library.
This requires that Timber be be installed as a plugin or included in your theme.
To use a Twig template for your query output, simply use the ‘twig_template’ parameter instead of the ‘lens’ parameter, and provide the path to your template:
[query twig_template=”folder/template-name.twig”]

各版本下載點

  • 方法一:點下方版本號的連結下載 ZIP 檔案後,登入網站後台左側選單「外掛」的「安裝外掛」,然後選擇上方的「上傳外掛」,把下載回去的 ZIP 外掛打包檔案上傳上去安裝與啟用。
  • 方法二:透過「安裝外掛」的畫面右方搜尋功能,搜尋外掛名稱「Custom Query Shortcode」來進行安裝。

(建議使用方法二,確保安裝的版本符合當前運作的 WordPress 環境。


0.3 | 0.2.2 | 0.2.3 | 0.2.4 | 0.2.5 | 0.4.0 | trunk |

延伸相關外掛(你可能也想知道)

  • PS Auto Sitemap 》PS Auto Sitemap 是一個 WordPress 外掛,自動從您的 WordPress 網站生成網站地圖頁面。, 對於初學者來說,安裝非常容易;對於專家來說,定制也非常容易。您...。
  • Post Type Switcher 》這個外掛在文章編輯介面中新增了一個簡單的文章型別下拉選單,讓你可以重新指派任何文章至新的文章型別。你可以在編輯文章時更換文章的型別。, 支援的型別, ...。
  • Post Duplicator 》這個外掛是用來製作選定文章的完全一模一樣複製。它支援自訂文章類型、自訂分類和自訂欄位。, *注意: 評論不會被複製到新文章。, 這個外掛的目的是為了快速且...。
  • Optimize Database after Deleting Revisions 》這個外掛是一個「一鍵式」WordPress資料庫清理/優化器。, 主要功能, , 刪除文章、頁面和/或自訂文章類型的修訂版本(您可以選擇保留最近的「X」個修訂版本,...。
  • Advanced Excerpt 》這個外掛可以改進 WordPress 原有的摘錄文章功能。, , 保留摘錄中的 HTML 標記,並可自選需要保留的標記, 按字元數或字數截斷摘錄, 只計算「真正的」文字(HT...。
  • Add From Server 》這個外掛提供有限的支援。請不要期望有太多新功能或修正 bug。功能可能隨時被移除。, Add From Server 外掛旨在幫助緩解不好的網站主機所造成的困擾,讓您可...。
  • Page and Post Clone 》這個外掛可以透過一個按鈕來複製貼文或頁面,現在您不必從零開始進行新頁面或貼文的樣式設計。, 這個外掛的主要功能包括:, , 建立一個頁面複本,保留所有內...。
  • WP Page Widget 》這款外掛讓小工具的選擇變得更加容易。啟用此外掛後,我們可以選擇要顯示在特定頁面/文章/自訂文章類型中的小工具。, 請注意,使用此外掛時必須啟用側邊欄主題。。
  • WP Total Hacks 》WP Total Hacks 可以在您的 WordPress 網站上自訂超過 20 個設置。, 此外掛已在 GitHub 上發布。, 一些功能:, 您可以選擇啟用或停用所有項目。, 需要 PHP5!...。
  • Revision Control 》**本外掛不提供支援。仍可使用,但請勿期待得到支援要求的回應或對「這無法運作」進行回應。**, Revision Control 是 WordPress 的一款外掛,可以讓使用者更...。
  • Reveal IDs 》WordPress 2.5版本發佈後,所有管理頁面的ID都被刪除了。這應該是因為普通用戶不需要它們。但對於高級WordPress用戶和開發人員來說,這些ID對某些外掛或模板...。
  • Bulk Delete 》Bulk Delete 是一個 WordPress 外掛,可以根據不同的條件和過濾器批次刪除文章、頁面、附件、使用者和元資料。此外掛支援以下條件和過濾器:, , 刪除文章, , ...。
  • WP Admin UI Customize 》, 儀表板, 顯示選項標籤, 輸出 - 元網站, 管理工具列 (Toolbar), 側邊選單 (Side menu), 元箱的管理, 登入畫面, 其他功能, , 這些自訂化都是可以實現的。, , ...。
  • Themify Portfolio Post 》Themify Portfolio Posts 是一個簡單的外掛,允許您展示乾淨版面的專案資訊。簡約而精美,您可以點擊您的圖庫專案的每張圖片,選擇顯示更多細節,例如專案類...。
  • Essential Content Types 》Essential Content Types 是一個 WordPress 外掛程式,讓您可以在您的網站上以不同的內容/文章類型展示出優秀的內容。這些內容/文章類型可能會被 WordPress ...。

文章
Filter
Apply Filters
Mastodon