內容簡介
這個外掛提供了 [query] 短碼,使你可以輸出按照特定條件篩選的文章。你可以自定義輸出格式,甚至可以在可定制的列和行網格中顯示結果。
還支援“鏡頭”(lenses),可以將查詢結果轉換成選項卡、手風琴或者輪播小工具。這個功能需要 Bootstrap 库已經在頁面上載入,在插件中並未包含。(如果需要,可以使用Bootstrap plugin)你可以在主題中創建新的鏡頭或覆蓋內置的鏡頭,以自定義輸出。
用法
你可以使用所有由WP_Query class支援的參數來篩選文章。你可以查詢特定的文章類型、分類、標籤、作者,等等。同時你需要定義你如何格式化輸出:
[query posts_per_page=”5″ cat=”3″]
{TITLE} ({COMMENT_COUNT})
[/query]
上述短碼將顯示最新的 5 個來自 ID 為 3 的分類的文章標題。可用的關鍵字包括:TITLE、CONTENT、AUTHOR、AUTHOR_URL、DATE、THUMBNAIL、CONTENT、COMMENT_COUNT等,將來還會添加更多選項。
網格顯示
使用“cols”參數可以在網格中顯示輸出。因此,這個短碼:
[query posts_per_page=”3″ cols=”3″] {THUMBNAIL}
{TITLE}
{CONTENT} [/query]
將在 3 列中使用指定模板顯示最新的 3 篇文章。如果在上面的片段中將帖子每頁顯示的選項設置為 6,它將顯示最新的 6 篇文章,每行有 3 列。
鏡頭
使用“lens”參數,可以在選項卡、手風琴或輪播小工具中顯示查詢結果。例如:
[query posts_per_page=”0″ post_type=”faq” lens=”accordion”]
這將為“faq”文章類型的所有文章創建手風琴小工具。這將創建一個最新的並且帶有五個特色文章的輪播小工具:
[query posts_per_page=”5″ featured=”true” lens=”carousel”]
支援的其他參數
除了 WP_Query 參數之外,此短碼還支援其他參數:
featured: 查詢置頂文章,默認情況下這些文章被排除在查詢之外。
thumbnail_size: 指定 {THUMBNAIL} 圖像的大小。你可以使用內置的圖像大小或自定義的大小。
content_limit: 限制 {CONTENT} 變數的字數;默認為“0”,表示輸出全部內容。
posts_separator: 用於在各個文章之間顯示的文字。
外掛標籤
開發者團隊
原文外掛簡介
This plugin gives you [query] shortcode which enables you to output posts filtered by specific attributes. You can format the output to your liking and even display the results in a grid of customizable columns and rows.
Also supports “lenses” which can turn your query results into Tabs, Accordion, or Carousel widgets. This feature relies on Bootstrap library to be already loaded on the page, the plugin does not include it (for that you can use the Bootstrap plugin). You can create new lenses or override the built-in ones in your theme to customize the output.
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. You also have to define how you want to format the output:
[query posts_per_page=”5″ cat=”3″]
{TITLE} ({COMMENT_COUNT})
[/query]
The above shortcode will display the title of the latest 5 posts from the category with the ID of 3. Available keywords are: TITLE, CONTENT, AUTHOR, AUTHOR_URL, DATE, THUMBNAIL, CONTENT, COMMENT_COUNT and more to be added later.
Grid display
With the “cols” parameter you can display the output in a grid. So this:
[query posts_per_page=”3″ cols=”3″] {THUMBNAIL}
{TITLE}
{CONTENT} [/query]
will display the latest 3 posts in the defined template, in 3 columns. If in the above snippet we set the posts_per_page option to 6, it will display the latest 6 posts in two rows that each has 3 columns.
Lenses
With the “lens” parameter you can display the query results in a Tab, Accordion, or Carousel widget. Example:
[query posts_per_page=”0″ post_type=”faq” lens=”accordion”]
This will create an accordion widget of all our posts from the “faq” post type. This creates a carousel of latest five featured posts:
[query posts_per_page=”5″ featured=”true” lens=”carousel”]
Other supported parameters
Aside from wp_query parameters, the shortcode also supports 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.
