Site logo

Blog

Stay up to date with what's going on at GeneratePress.

Archived topic

Query Loop to display posts for further reading within blog post

7 replies · Started by lerschiboi on December 17, 2022

Viewing posts 1–8 of 8

Hi,

Within my blog posts, I like to display posts for further reading here and there in a visually appealing way.

I currently do this in a cumbersome way and would like to switch to query loops to achieve it.

I've come so far as to insert a query loop in a post and select the query parameter "include posts," which allowed me to pick the posts I wanted.

But what I don't get is how I can style these query loops globally.

I tried using a Content Template Element and choosing all posts as the location, but then the entire blog posts get overwritten with that template, so this is clearly not how it's done.

Can you point me in the right direction?

Hi there,

are you using GenerateBlocks Pro ?

Hi, yes I am

Hi Lars,

If it's creating Related Posts you are looking for there's a way to do it with GB Pro, here's an article you may refer to: https://generateblocks.com/creating-related-posts-with-query-loop-block/

As for adding them Globally, using a Block Element is indeed a good way to do it. You can use a Block Element - Hook and hook it to somewhere like after_content. You can see some other hooks you can use here: https://docs.generatepress.com/article/hooks-visual-guide/

In this way, you wouldn't override the main query.

With GB Pro, you can also opt to start from a Pattern. See here for available Patterns: https://generateblocks.com/library/

More on Pattern Library here: https://docs.generateblocks.com/article/pattern-library-overview/

Hi Fernando,

Thanks but that's not quite what I'm looking for. I'm not looking for a related posts section at a specific part of my blog posts.

Instead, I want to sprinkle these further reading posts throughout my blog posts wherever it fits. Sometimes I want to reference one post, sometimes two or three. But the posts should always be styled as seen in my screenshot above.

Query loops seem to be a good starting point as they let me choose specific posts via the "include posts" parameter.

I can now style this query loop, but I don't want to do this for every single post. Is there a way to do this globally?

If you're using GenerateBlocks Pro, then you can create a Local Pattern to save your Query Loop. Then you can just add that local pattern each time you require it.
You may also want to creating the GB Global Styles first and building your local template with them first, in case you want to refresh their design in the future.

Thanks David, that works

You're welcome

This archived topic is closed to new replies.