Join the Webstudio community

Updated 6 months ago

How to Display Related Posts?

At a glance
I got a multiple category blog and on the dynamic post page I'm attempting to create a footer section to display related posts based on the category of the current post. The post variable resource (located in the body) contains the category value along with all the blog post data (title, content, dates, etc.) and is matching correctly with the dynamic slug.

The problem is that for the related posts footer I can't find a way to let the related posts collection component filter out posts using the category value that coming from the Post Variable Resource (in the body).

Is there a way to add data from the first collection (Post Variable Resource) to the second collection (Related Post Resource)?

In the screenshot attached I need to dynamically add the category value from the Post Variable Resource into "value": "my-url-slug" which is in the Related Post Resource.

Any pointers on how to accomplish this would be greatly appreciated.
Attachment
RelatedPost.jpg
O
L
10 comments
it would mean nested Resources which we currently don't support
one way to potentially do it is to render related once only on the client
meaning rendering category from resource as an attribute in some div, then using custom js to fetch related once
another option is to have category in the url, then its 2 consequent Resource fetching and second one can read from system params the category
another option is to have. a custom backend that stitches requests together and provdes everything in one request to webstudio - then is server rendered
that is f your cms can't give you all that in one response
This is how I have it in the dynamic category page. Since the category is in the url is easy to filter the matching related posts. However in the post page I can't do that because the category does not exist in the url.
well you could make it exist in the url)
This might work because I already have a div component that has a breadcrumb with all the categories. Going to explore this further.
I can custom code the CMS I'm using to whatever I need so this might be a good alternative to explore.
Add a reply
Sign up and join the conversation on Discord