Can a range of posts be displayed depending the current post being viewed?

Hi there. I have created a layout for displaying single posts using Layout Builder and Loopers. Within this layout, I would like to add a section that displays other posts of the same series. E.g let’s say I have created posts A, B, C, D and E and I have given A, B and C the same taxonomy. When viewing post A (the full post), I would like to have section below that displays a preview of posts B and C. Can this be done using Loopers?

Hi Ryan,

Thank you for writing in, on the bottom of your single layout you can have a Query String type Looper provider, and use the query below.

category_name={{dc:term:name}}&post_type=post&posts_per_page=6&offset=0&ignore_sticky_posts=1&post__not_in%5B0%5D={{dc:post:id}}

The category_name={{dc:term:name}} is the part where it filter the result by category.

Hope it helps,
Cheers!

Thanks very much, this works perfectly for posts that I have categorized. The only issue I have now is when I view a post that is uncategorized, this new row displays all other posts that are also uncategorized. How can I set it so this row is hidden when it is uncategorized?

I have a taxonomy called Genres then have items within it. Could it be done using these instead so it doesn’t pick up on the default ‘Uncategorized’ category?

Hi Ryan,

You can update the query with the one below to exclude the uncategorized posts

category_name={{dc:term:name}}&post_type=post&posts_per_page=6&offset=0&ignore_sticky_posts=1&post__not_in%5B0%5D={{dc:post:id}}&category__not_in%5B0%5D=1

Hope it helps,
Cheers!

Perfect! Thanks very much. One last thing I hope you can help with. I have these posts set up in a column, with a text element above it (in the same column) with text along the lines of “Check out these other books in the same series”. Am I able to set this entire column to be hidden if there are no posts to display? At the moment the posts don’t display if they are uncategorized but the text element above it is still there. Thanks again!

Hello @rhinotago,

You can use this {{dc:query:found_posts}} dynamic content code. It would return the number of posts found in the query. After that, you can set the condition like this

To set the condition you need to go to the Text element —>Customize —>Condition—>Edit.

You may check our doc of assignment operator

Hope it helps
Thanks

Can you please clarify where I need to use the code {{dc:query:found_posts}}? I am wanting to hide the entire column (which includes the text element and the posts), so will it work if I apply the above condition to the whole column?

Hi Ryan,

On the Text element’s Customize > Conditions tab, set a condition that will compare a number (https://i.imgur.com/h6Mri1H.png)

On the left side, you place {{dc:query:found_posts}} the operator will be == or >= on the right side is 0, it looks like the screenshot provided above.

But please note that this is not going to work if the text is outside of your Looper provider.

Cheers!

Hi there. Some post categories are working but some aren’t. Would you mind having a look and seeing what the issue is? I will send a secure note with details.

Hi Ryan,

This should be fixed now, I ended up using the Genre taxonomy instead of category. So the related notebook should be base on genre now, not on category.

Here is the final query string.

post_type%5B0%5D=post&posts_per_page=6&ignore_sticky_posts=1&tax_query%5B0%5D%5Btaxonomy%5D=genres&tax_query%5B0%5D%5Bterms%5D={{dc:term:slug}}&tax_query%5B0%5D%5Bfield%5D=slug&tax_query%5B0%5D%5Boperator%5D=IN&tax_query%5B0%5D%5Binclude_children%5D=0&post__not_in%5B0%5D={{dc:post:id}}

Hope it helps,
Cheers!

1 Like

Brilliant! Thank you so much.

I have one last question. Just let me know if I should enter it as a new topic.

Am I able to format the post button to match the other buttons on my site, as the button settings within the post element appear to be very restrictive?

Hi Ryan,

Not sure what exactly you trying to point by saying Post Button, is it a button within the Post element? If that is the case, you can adjust the style like other Button elements. You can also save other Button element styles as Preset and apply it to the Post Button.

If that is not the case and you are trying to point out something else, please provide any screenshot marked with the issue or any video that help us to recognize the problem.

Hope it helps.
Thanks

Hi there. Yes, I am referring to the button within Posts. The first image shows the button options when creating a post and the second image shows how the button appears on the site (and shows the button style I would like to replicate).

Hi Ryan,

Please create a new post about this new issue as this one is getting longer and hard to follow.

Thank you for understanding,

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.