{"id":1673,"date":"2021-01-25T11:49:51","date_gmt":"2021-01-25T09:49:51","guid":{"rendered":"https:\/\/creativethemes.com\/blocksy\/?post_type=documentation&#038;p=1673"},"modified":"2024-04-24T15:34:20","modified_gmt":"2024-04-24T12:34:20","slug":"blocksy-posts-shortcode","status":"publish","type":"documentation","link":"https:\/\/creativethemes.com\/blocksy\/docs\/developers-general-developers\/blocksy-posts-shortcode\/","title":{"rendered":"[blocksy_posts] shortcode"},"content":{"rendered":"\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-4-3 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"How to Use the [blocksy_posts] Shortcode | Advanced Tutorial\" width=\"1290\" height=\"968\" src=\"https:\/\/www.youtube.com\/embed\/6hVUlto_a1o?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<p>Starting with <strong><em>Blocksy Companion 1.7.49<\/em><\/strong> there is the blocksy posts shortcode made available for usage. This shortcode is very useful in combination with Gutenberg or with other page builders, when you want to quickly display a list of posts on custom pages or other dynamic locations. Most important features of it:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Easy to use<\/li>\n\n\n\n<li>Uses Blocksy&#8217;s archive templates so the same styles apply<\/li>\n\n\n\n<li>Custom post type support<\/li>\n\n\n\n<li>Inherits Customizer settings for the picked custom post type<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Available arguments:<\/h2>\n\n\n\n<ol class=\"is-style-default wp-block-list\">\n<li><code><strong>post_type<\/strong><\/code> &#8211; needed post type (comma separated format if more than one post type).<br><em>Note: If multiple post types provided, the customizer settings of the first one will be respected.<\/em>\n<ul class=\"wp-block-list\">\n<li>Example: <code>book,movie,song<\/code><\/li>\n\n\n\n<li>Default value<strong>: <\/strong><code>post<\/code><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><code><strong>limit<\/strong><\/code> &#8211; Amount of posts to display per page.\n<ul class=\"wp-block-list\">\n<li> Default value<strong>: <\/strong>5<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><code><strong>orderby<\/strong><\/code> &#8211; Sorting logic.\n<ul class=\"wp-block-list\">\n<li>Possible values<strong>: <\/strong><code>post_date<\/code>, <code>comment_count<\/code>, <code>rand<\/code>. Everything accepted in <a href=\"https:\/\/developer.wordpress.org\/reference\/classes\/wp_query\/#order-orderby-parameters\" rel=\"nofollow noopener\" target=\"_blank\">WP_Query <code>orderby<\/code><\/a><\/li>\n\n\n\n<li>Default value<strong>: <\/strong><code>post_date<\/code><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><code><strong>order<\/strong><\/code> &#8211; Sorting order.\n<ul class=\"wp-block-list\">\n<li>Possible values<strong>: <\/strong><code>DESC<\/code>, <code>ASC<\/code> Everything accepted in <a href=\"https:\/\/developer.wordpress.org\/reference\/classes\/wp_query\/#order-orderby-parameters\" rel=\"nofollow noopener\" target=\"_blank\">WP_Query <code>order<\/code><\/a><\/li>\n\n\n\n<li>Default value<strong>: <\/strong><code>DESC<\/code>.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><code><strong>term_ids<\/strong><\/code> &#8211; ID of the terms to display posts from. In comma separated format, different taxonomies can be mixed.\n<ul class=\"wp-block-list\">\n<li>Example<strong>: <\/strong><code>23,15,38<\/code> <\/li>\n\n\n\n<li>Default value<strong>: <\/strong><code>null<\/code><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><code><strong>exclude_term_ids<\/strong><\/code> &#8212; ID of the terms to exclude the posts from. Same format as <code>term_ids<\/code>.<\/li>\n\n\n\n<li><code><strong>post_ids<\/strong><\/code> &#8211; Specific IDs of the posts to display. In comma separated format\n<ul class=\"wp-block-list\">\n<li>Example<strong>: <\/strong><code>12,13,18<\/code> <\/li>\n\n\n\n<li>Default value<strong>: <\/strong><code>null<\/code><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><code><strong>has_pagination<\/strong><\/code> &#8211; Display or hide the pagination\n<ul class=\"wp-block-list\">\n<li>Possible values<strong>: <\/strong><code>yes<\/code>, <code>no<\/code><\/li>\n\n\n\n<li>Default value<strong>: <\/strong><code>yes<\/code><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><code><strong>ignore_sticky_posts<\/strong><\/code> &#8211; Ignore or display the sticky posts\n<ul class=\"wp-block-list\">\n<li>Possible values<strong>: <\/strong><code>yes<\/code>, <code>no<\/code><\/li>\n\n\n\n<li>Default value<strong>: <\/strong><code>no<\/code><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><code><strong>view<\/strong><\/code> &#8211; Display shortcode as a slider or as an archive.\n<ul class=\"wp-block-list\">\n<li>Possible values: <code>slider<\/code>\/<code>archive<\/code><\/li>\n\n\n\n<li>Default value: <code>archive<\/code><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><code><strong>slider_image_ratio<\/strong><\/code> &#8211; When <code>view: slider<\/code>, decide which ratio the images will have.\n<ul class=\"wp-block-list\">\n<li>Possible values: <code>1\/1<\/code>, <code>2\/1<\/code>, <code>16\/9<\/code>, <code>4\/3<\/code>, <code>1\/2<\/code>, <code>9\/16<\/code>, <code>3\/4<\/code><\/li>\n\n\n\n<li>Default value: <code>2\/1<\/code><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><code><strong>slider_autoplay<\/strong><\/code> &#8211; Enable or disable slider autoplay for slider.\n<ul class=\"wp-block-list\">\n<li>Possible values: <code>number<\/code>\/<code>no<\/code><\/li>\n\n\n\n<li>Default value: <code>no<\/code><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><code><strong>no_results<\/strong><\/code> &#8211; Decide how to handle the no posts state.\n<ul class=\"wp-block-list\">\n<li>Possible values: <code>404<\/code>\/<code>skip<\/code>\n<ul class=\"wp-block-list\">\n<li><code>404<\/code> &#8211; output the regular 404 template<\/li>\n\n\n\n<li><code>skip<\/code> &#8211; output nothing.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Default value: <code>404<\/code><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><code><strong>filtering<\/strong><\/code> &#8211; Enables the filter options from the Post Types Extra extension\n<ul class=\"wp-block-list\">\n<li>Possible values: <code>yes\/no<\/code>\n<ul class=\"wp-block-list\">\n<li>yes &#8211; displays the filters<\/li>\n\n\n\n<li>no &#8211; hides the filters<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Default value: no.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><code><strong>class<\/strong><\/code> &#8211; Add a custom class to the main container wrapper.<\/li>\n<\/ol>\n\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">Usage examples:<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>&#091;blocksy_posts limit=\"4\"]<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Posts from certain categories<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>&#091;blocksy_posts term_ids=\"10,25,48\"]<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Different custom post type<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>&#091;blocksy_posts post_type=\"portfolio\"]<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Posts without pagination<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>&#091;blocksy_posts post_type=\"movies\" limit=\"8\" has_pagination=\"no\"]<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Posts with content before the listing<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>&#091;blocksy_posts]&lt;h3&gt;My posts&lt;\/h3&gt;&#091;\/blocksy_posts]<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Slider view<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>&#091;blocksy_posts view=\"slider\" limit=\"10\"]<\/code><\/pre>\n\n\n\n<div class=\"wp-block-group has-background is-layout-constrained wp-block-group-is-layout-constrained\" style=\"border-radius:4px;background-color:#ebf2f3\">\n<h5 class=\"wp-block-heading\"><strong><strong>Important Notice!<\/strong><\/strong><\/h5>\n\n\n\n<p class=\"is-style-info coblocks-alert-paragraph\">The <code>blocksy_posts<\/code> slider shortcode does not display its styling out of the box, if WooCommerce isn\u2019t loaded. This is due to performance reasons. It can easily be enabled back, without installing WooCommerce by integrating the following&nbsp;<a href=\"https:\/\/gist.github.com\/andreiglingeanu\/1f2c87bcb4d64151aa0f34afc97ca70b\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">snippet<\/a>&nbsp;inside of the functions.php file of your Child theme.<\/p>\n<\/div>\n\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"change-query-args\">Change WP_Query args for all shortcodes at once<\/h2>\n\n\n\n<p><strong>Name: <\/strong><code>blocksy:general:shortcodes:blocksy-posts:args<\/code><br><strong>Type:<\/strong> Filter<br><strong>Arguments:<\/strong> 1<br><strong>Description:<\/strong> Change WP_Query arguments for blocksy_posts shortcode. <em>Since 1.8.4<\/em><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">How to change the query for an individual shortcode:<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ &#091;blocksy_posts shortcode_instance=\"instance-1\"]\nadd_filter(\n\t'blocksy:general:shortcodes:blocksy-posts:args',\n\tfunction ($query_args, $shortcode_args) {\n\t\tif (\n\t\t\t! isset($shortcode_args&#091;'shortcode_instance'])\n\t\t\t||\n\t\t\t$shortcode_args&#091;'shortcode_instance'] !== 'instance-1'\n\t\t) {\n\t\t\treturn $query_args;\n\t\t}\n\n\t\t$query_args&#091;'offset'] = 5;\n\n\t\treturn $query_args;\n\t},\n\t10, 2\n);\n\n\/\/ &#091;blocksy_posts shortcode_instance=\"instance-2\"]\nadd_filter(\n\t'blocksy:general:shortcodes:blocksy-posts:args',\n\tfunction ($query_args, $shortcode_args) {\n\t\tif (\n\t\t\t! isset($shortcode_args&#091;'shortcode_instance'])\n\t\t\t||\n\t\t\t$shortcode_args&#091;'shortcode_instance'] !== 'instance-2'\n\t\t) {\n\t\t\treturn $query_args;\n\t\t}\n\n\t\t$query_args&#091;'offset'] = 10;\n\n\t\treturn $query_args;\n\t},\n\t10, 2\n);<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Starting with Blocksy Companion 1.7.49 there is the blocksy posts shortcode made available for usage. This shortcode is very useful in combination with Gutenberg or with other page builders, when you want to quickly display a list of posts on custom pages or other dynamic locations. Most important features of it: Available arguments: Usage examples: [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"_acf_changed":false,"footnotes":""},"doc_categories":[122],"class_list":["post-1673","documentation","type-documentation","status-publish","hentry","doc_categories-developers-general-developers"],"blocksy_meta":{"styles_descriptor":{"styles":{"desktop":"","tablet":"","mobile":""},"google_fonts":[],"version":6}},"acf":[],"_links":{"self":[{"href":"https:\/\/creativethemes.com\/blocksy\/wp-json\/wp\/v2\/documentation\/1673","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/creativethemes.com\/blocksy\/wp-json\/wp\/v2\/documentation"}],"about":[{"href":"https:\/\/creativethemes.com\/blocksy\/wp-json\/wp\/v2\/types\/documentation"}],"author":[{"embeddable":true,"href":"https:\/\/creativethemes.com\/blocksy\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/creativethemes.com\/blocksy\/wp-json\/wp\/v2\/comments?post=1673"}],"version-history":[{"count":11,"href":"https:\/\/creativethemes.com\/blocksy\/wp-json\/wp\/v2\/documentation\/1673\/revisions"}],"predecessor-version":[{"id":10335,"href":"https:\/\/creativethemes.com\/blocksy\/wp-json\/wp\/v2\/documentation\/1673\/revisions\/10335"}],"wp:attachment":[{"href":"https:\/\/creativethemes.com\/blocksy\/wp-json\/wp\/v2\/media?parent=1673"}],"wp:term":[{"taxonomy":"doc_categories","embeddable":true,"href":"https:\/\/creativethemes.com\/blocksy\/wp-json\/wp\/v2\/doc_categories?post=1673"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}