Beskriuwing
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).
This will show the latest 3 posts in a tabbed widget.
[query posts_per_page=”3″ lens=”tabs”]
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”]
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”]
Skermôfbyldings
Ynstallaasje
- Upload the whole plugin directory to the
/wp-content/plugins/
directory - Activate the plugin through the ‘Plugins’ menu in WordPress
- Now use
[query]
shortcode anywhere you want. - Enjoy!
FAQ
no questions have been asked yet.
Resinsjes
Meiwurkers & amp; Untwikkelders
“Custom Query Shortcode” is iepen boarne software. De folgjende minsken hawwe bydroegen oan dizze plugin.
MeiwurkersOersette “Custom Query Shortcode” yn jo taal.
Ynteressearre yn ûntwikkeling?
Blêdzje troch de koade , besjoch de SVN-repository , of abonnearje op it ûntwikkelingslogboek troch RSS .
Feroaringslog
0.4.0
- Added Twig templating support via the Timber Library
0.3
- Added a new directory to search for lenses within the current theme – ‘query-shortcode-templates’
- Revamped readme.txt documentation
0.2.5
- Changed lens ‘ul’, removing post date. I also added lens ‘ul-title-date’, which is the equivalent of the previous ‘ul’ lens.
0.2.4
- Added lens ‘ul’, presenting an unordered list of query results with post date displayed.
0.2.3
- Added lens ‘article-excerpt-date’, which is the same as ‘article-excerpt’, except with the post date displayed.
0.2.2
- Added a filter to allow shortcodes within widget areas, which makes this plugin a lot more useful.
0.2.1.1
- Added a second directory to search for lenses within the current theme – ‘partials/custom-query-lenses’.
0.2.1
- Added posts_separator parameter.
0.2
- Added Lens functionality. Now you can build tabs, accordions, and carousels (and build custom ones) out of queried posts. Relies on Twitter Bootstrap framework.