开发者 |
peterhebert
shazdeh |
---|---|
更新时间 | 2021年4月11日 03:08 |
PHP版本: | 3.3 及以上 |
WordPress版本: | 5.7 |
版权: | GPLv2 |
版权网址: | 版权信息 |
[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:
[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:
[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 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"]
/wp-content/plugins/
directory[query]
shortcode anywhere you want.