Archived topic
how to create related posts with generateblocks?
27 replies · Started by eran on July 17, 2022
Hi, how can i make related posts in the right sidebar that when im in a page the sidebar will show all the brothers page of the page?
plus, if im in the parent page i want to display all the child pages.
is it possible with generateblocks?
Hi Eran,
It can be achieved through a Query Loop Block from GenerateBlocks 1.5.4 and GB Pro 1.3.0.
Reference: https://docs.generateblocks.com/article/query-loop-overview/
Otherwise, you’ll need custom code to achieve as such through GB.
Hope this clarifies!
I understand.
But I don't know how to achieve it.
What should I chhose in the parameters?
You can try Taxonomies > Categories > Current Post terms. Example: https://share.getcloudapp.com/Z4uApkjw
Hope this clarifies!
But I don't use categories on my menu i use pages. it will still work?
You’re right, it wouldn’t work.
Try Parent > Current Post to show all Child pages: https://share.getcloudapp.com/6quzweGg
Then, to get all siblings, add my-query to the Grid Block of the Query Loop, and add this PHP snippet:
add_filter( 'generateblocks_query_loop_args', function( $query_args, $attributes ) {
if ( ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'my-query' ) !== false ) {
global $post;
$query_args['post_parent'] = $post->post_parent;
}
return $query_args;
}, 10, 2 );
Adding PHP reference: https://docs.generatepress.com/article/adding-php/#code-snippets
Kindly let us know how it goes.
I need to add "my-query" to the grid block as a class?
Yes, that’s correct. Example: https://share.getcloudapp.com/kpu8Rbeq
I dont have the option for current post.
I try to make this through generatepress elements.
Hi there,
if you want to display the Child pages, then the Parameter is: Parent -> Current Post
See here:
https://generateblocks.com/creating-related-posts-with-query-loop-block/
Check the Index of child pages example
NOTE: This is a GenerateBlocks Pro feature and requires version 1.30 which is in Alpha:
Yes I have the generateblocks pro Version 1.5.4
I dont have the option current post.
I can choose a single page but i want this to apply on all the pages.
GenerateBlocks Pro is only up to version 1.3
https://generateblocks.com/generateblocks-pro-1-3-0/
Its a separate plugin.
Version 1.5.4 is the free version.
oh now I see.
why I didnt get a message for the update?
every update I need to download the update from the generateblocks website?
In the GenerateBlock settings, you need to have your license key added and saved and the Receive beta updates toggle enabled if you want to see the alpha/beta updates.
I update for 1.3 version
its still doesnt work.