Extend fiddle of core/post-template
to display related posts when className
attribute is related
#36
Labels
enhancement
New feature or request
In the UK WP Community Slack #support channel Jamie Glasspool specified his requirements to extend the WordPress Query loop.
In my main post template I want to list the three most recent posts in the same category as the current post (while also excluding the current post itself). In the page builder, doing this was simply a case of adding a blog posts module and choosing to filter the results based on 'current category' from a dropdown.
This doesn't appear to be supported in the default Wordpress Query Loop block and I'm having no joy working out how best to do it, nor finding anyone else who's tried the same thing. Ideally I would like to simply create this functionality and add it as a tick box to the existing Query Loop block under Filters or create a block variation that had this built in.
I'm surprised that showing 'related posts' is not a common enough feature that there isn't an existing solution out there I can borrow from.
Proposed solution
core/post-template
server side rendering when theclassName
attribute is set torelated
.The fiddle function will be something like this
Explanation
functions.php
requires the/includes/block-overrides.php
fileincludes/block-override-functions.php
render_callback
function inthisis_maybe_override_block()
if
can be commented outregister_block_type_args
filter, which is called for each block registered.core/post-template
is implemented inincludes\post-template.php
asthisis_render_block_core_post_template()
.If not using Gutenberg remove the
gutenberg_
prefix to the call to peform the actual rendering of the post-template.In the fiddle function
If the $className is 'related' then
Testing notes
In my local test I just implemented the Query loop within a post
The original category is 1 "uncategorised".
The text was updated successfully, but these errors were encountered: