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:
- Easy to use
- Uses Blocksy’s archive templates so the same styles apply
- Custom post type support
- Inherits Customizer settings for the picked custom post type
Available arguments:
post_type
– needed post type (comma separated format if more than one post type).
Note: If multiple post types provided, the customizer settings of the first one will be respected.- Example:
book,movie,song
- Default value:
post
- Example:
limit
– Amount of posts to display per page.- Default value: 5
orderby
– Sorting logic.- Possible values:
post_date
,comment_count
,rand
. Everything accepted in WP_Queryorderby
- Default value:
post_date
- Possible values:
order
– Sorting order.- Possible values:
DESC
,ASC
Everything accepted in WP_Queryorder
- Default value:
DESC
.
- Possible values:
term_ids
– ID of the terms to display posts from. In comma separated format, different taxonomies can be mixed.- Example:
23,15,38
- Default value:
null
- Example:
exclude_term_ids
— ID of the terms to exclude the posts from. Same format asterm_ids
.post_ids
– Specific IDs of the posts to display. In comma separated format- Example:
12,13,18
- Default value:
null
- Example:
has_pagination
– Display or hide the pagination- Possible values:
yes
,no
- Default value:
yes
- Possible values:
ignore_sticky_posts
– Ignore or display the sticky posts- Possible values:
yes
,no
- Default value:
no
- Possible values:
view
– Display shortcode as a slider or as an archive.- Possible values:
slider
/archive
- Default value:
archive
- Possible values:
slider_image_ratio
– Whenview: slider
, decide which ratio the images will have.- Possible values:
1/1
,2/1
,16/9
,4/3
,1/2
,9/16
,3/4
- Default value:
2/1
- Possible values:
slider_autoplay
– Enable or disable slider autoplay for slider.- Possible values:
number
/no
- Default value:
no
- Possible values:
no_results
– Decide how to handle the no posts state.- Possible values:
404
/skip
404
– output the regular 404 templateskip
– output nothing.
- Default value:
404
- Possible values:
filtering
– Enables the filter options from the Post Types Extra extension- Possible values:
yes/no
- yes – displays the filters
- no – hides the filters
- Default value: no.
- Possible values:
class
– Add a custom class to the main container wrapper.
Usage examples:
[blocksy_posts limit="4"]
Posts from certain categories
[blocksy_posts term_ids="10,25,48"]
Different custom post type
[blocksy_posts post_type="portfolio"]
Posts without pagination
[blocksy_posts post_type="movies" limit="8" has_pagination="no"]
Posts with content before the listing
[blocksy_posts]<h3>My posts</h3>[/blocksy_posts]
Slider view
[blocksy_posts view="slider" limit="10"]
Important Notice!
The blocksy_posts
slider shortcode does not display its styling out of the box, if WooCommerce isn’t loaded. This is due to performance reasons. It can easily be enabled back, without installing WooCommerce by integrating the following snippet inside of the functions.php file of your Child theme.
Change WP_Query args for all shortcodes at once
Name: blocksy:general:shortcodes:blocksy-posts:args
Type: Filter
Arguments: 1
Description: Change WP_Query arguments for blocksy_posts shortcode. Since 1.8.4
How to change the query for an individual shortcode:
// [blocksy_posts shortcode_instance="instance-1"]
add_filter(
'blocksy:general:shortcodes:blocksy-posts:args',
function ($query_args, $shortcode_args) {
if (
! isset($shortcode_args['shortcode_instance'])
||
$shortcode_args['shortcode_instance'] !== 'instance-1'
) {
return $query_args;
}
$query_args['offset'] = 5;
return $query_args;
},
10, 2
);
// [blocksy_posts shortcode_instance="instance-2"]
add_filter(
'blocksy:general:shortcodes:blocksy-posts:args',
function ($query_args, $shortcode_args) {
if (
! isset($shortcode_args['shortcode_instance'])
||
$shortcode_args['shortcode_instance'] !== 'instance-2'
) {
return $query_args;
}
$query_args['offset'] = 10;
return $query_args;
},
10, 2
);