Archived topic
Can I add a 'Related posts', ' GP section template' after articles?
9 replies · Started by Ema on February 9, 2022
Hello GP,
Can I design a GP section template for related posts, using the native Worpress posts loop, and add it beneath the article?
Or do I need to do this with a hook?
Best E
Hi Ema,
By GP Section template, do you mean the old Sections feature of GP Premium? If that's the case then I don't think that's usable as Sections can't be placed on hooks.
The best approach would be to get a have a related post loop (either from plugin or custom designed WP_query loop) and hook it beneath the article.
The related posts loop can be placed on either a Hook Element or a Block Element.
Or actually, you can even do the entire thing on a code snippets plugin as you simply have to wrap the entire thing into a function and have that function be hooked on a specific GP hook below the article.
For the related posts loop, we don't exactly have a plugin recommendation that can display related posts out of the box but we have some workarounds with WP Show Posts which can be found here in the forums. :D
Hi Elvin,
Thanks for your time.
i was looking Elements > Blocks > Content template >
Set up like this
But I don't think this section can be targeted underneath articles?
I have wp-show posts installed
The code I'm looking at is:
<div class="wpsp-related-posts1 grid-container">
<h2>Related Posts</h2>
<?php
if ( is_single() ) {
$cats = get_the_category();
$cat = $cats[0];
} else {
$cat = get_category( get_query_var( 'cat' ) );
}
$cat_slug = $cat->slug;
$list = get_page_by_title( 'related', 'OBJECT', 'wp_show_posts' );
wpsp_display( $list->ID, 'tax_term="' . $cat_slug . '"' );
?>
</div>
Hi there,
you can use this GIST:
https://gist.github.com/diggeddy/b71bf07aa55eecb0c34191f9fe05d224
it creates a shortcode that outputs a custom loop.
The default args are to show the latest 3 posts. If added/hooked into a single post it will get 3 posts within that category terms.
It outputs a HTML wrapper for the grid, and within the loop a hook: do_action('db_custom_post_loop'); you can use to add your block element template.
Hi!
I was just looking at your GIST David and some related posts info on WPSP.
(Your FlintSkin website is down btw).
Thank you, going to give this a go now.
Thanks, David
E
Glad to be of help.
Hi David,
Would I add main code PHP to Snippets or child theme, then the shortcode [db_custom_loop_shortcode] in via elements>hooks?
Very Best
E
1. The PHP Can go in either the Child Theme functions.php OR the code snippets plugin.
2. You can then add the [db_display_custom_post_loop] shortcode in the post editor or use a Hook Element to add it to where you need it.
3. The Block Element - Content Template you create for displaying the post template, you need to:
3.1 Change the Element Type to Hook.
3.2 Select the Hook > Custom Hook
3.3 Add this hook to the field provided: db_custom_post_loop
Hope that makes sense - its a bit of rabbit hole!
Thx for the headsup on the site... hell know how a maintenance page can break lol .
Thank you, David, you are an almanach.
This makes sense! Putting into practice now. So good!
I thought you may have some code for this kicking around and came across your site. It's no doubt because you are so busy sorting out everyone else's glitches.
Best E
Awesome - let me know how you get on with it :)