Skip to content

Posts Shortcode

Oliver Juhas edited this page May 15, 2019 · 5 revisions

Info

Displays list of posts of any post type.
You can enable a filter for displayed posts, or display posts in a carousel.


Example

Displays 4 newest Posts tagged with "My tag" (tag slug should be my-tag) in 4 columns:

[wm_posts post_type="post" columns="4" count="4" taxonomy="post_tag:my-tag" /]

Displays filtered Projects ordered by name in 3 columns (filter is set from Project Categories in this case):

[wm_posts post_type="wm_projects" order="name" columns="3" count="60" filter="project_category" /]

Parameters

Please note that you can omit parameters with empty values when writing the shortcode.

Parameter Type Value example    Description
class string my-class Adds a custom CSS class(es) onto shortcode wrapper.
columns predefined 1, 2, 3, 4, 5 or 6 Number of columns items are displayed in.
count integer 6 Number of items to display. From performance perspective it is not recommended to use a value of -1 to display all items, instead use 50, for example.
filter string taxonomy_key or taxonomy_key:term-slug If set, it enables the posts list filtering. You can use any taxonomy for filtering, but make sure the taxonomy is related to the post type you are displaying. For example, you can set category or post_tag for default WordPress Posts. You can further specify to display a filter from sub-categories of a specific parent category if you set a parent category slug, such as category:parent-category-slug-here (this logic can be applied for any hierarchical taxonomy).
filter_layout string masonry The filter uses Isotope JavaScript library and you can optionally set its layout here.
heading_tag predefined h2, h3, h4, h5 or h6 Sets the caption HTML heading tag for headings cascade control (for better accessibility).
image_size predefined thumbnail One of image sizes registered on your WordPress site.
no_margin boolean 0 (false) or 1 (true) Removes or minimizes the gap between the items. Your theme must provide the related styles.
order predefined custom, menuasc, menudesc, name, new, old or random Sets the order in which posts display. Default is new. The custom is synonym for menuasc. Also, it is not really recommended to use random as it slows down your website performance.
pagination boolean 0 (false) or 1 (true) Whether to display a multi-page navigation (pagination).
post_type string Any existing post type of your WordPress website, such as post or page. Use your website post type IDs (you can get it from your WordPress dashboard when editing a post type).
related string taxonomy_key If you display the shortcode on a single post page, you may use it for displaying related posts. Just specify the taxonomy that should be used for the relation. The taxonomy must be related to the post type you are using. You can use category for default WordPress Posts, for example. This is optional parameter.
scroll integer 0 or 1 or 5000 Enables horizontal carousel scrolling. 0 stands for disabled, 1 enables manual carousel, 1000 and more enables automatic carousel where the value sets the carousel pause in milliseconds (so, 5000 sets the carousel pause to 5 seconds, for example). Default is 0.
taxonomy string taxonomy_key:term-slug If you specify this parameter, only posts from specific term of a specific taxonomy are going to be displayed. You can use it to display default WordPress Posts from a specific category, for example. In that case you would set category:my-category-slug value. Please note that the taxonomy must be related to the post type you are displaying.

Compatibility

Please, make sure your theme supports this shortcode, before using it.
Some themes may not be compatible with certain shortcodes as they may use different approach to displaying similar elements. In that case the shortcode is displays in its raw code format on your website front-end.