Archived topic
Whats the best way to add a second loop on a page in blog format?
3 replies · Started by Samuel on October 26, 2017
I'm working on moving my site over to GP and my question is what is the best way to add a second loop on a page that displays in the blog format I have set. For example, on my existing site on a single page, after the post I display 6 related posts. For a page I list the 6 most recent posts at the bottom. I'm converting the site over from Genesis and it was fairly simple in Genesis because of a custom loop function. What's the best way to in GP to set a custom query and then run the loop again with the proper html to display in the blog format I have set in the customizer?
Hi there,
You would have to write a custom page template to do that, or hook in a custom function with a new loop using one of the hooks: https://docs.generatepress.com/collection/hooks/
Alternatively, you can use a plugin like this: https://wpshowposts.com/
Let me know if you need more info :)
That makes sense. I wanted to make sure this functionality didn't already exist before I looked at another way. I am looking at WP show posts and so far I love it.
I don't know how difficult it would be to implement, but it would be nice to have a function in a future version you could call to produce the html listing blog posts. Something would allow for custom query args.
Thanks!
You could likely just copy one of the existing loops, then alter the WP_Query args for your custom loop. Then all of the styling/HTML would be the same.
Glad you like the look of WPSP :)