- This topic has 9 replies, 3 voices, and was last updated 4 years, 1 month ago by
David.
-
AuthorPosts
-
February 9, 2022 at 3:28 am #2110443
Ema
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
February 9, 2022 at 3:57 am #2110486Elvin
StaffCustomer SupportHi 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. 😀
February 9, 2022 at 4:42 am #2110534Ema
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>February 9, 2022 at 6:11 am #2110648David
StaffCustomer SupportHi 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.February 9, 2022 at 6:20 am #2110657Ema
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
February 9, 2022 at 7:02 am #2110702David
StaffCustomer SupportGlad to be of help.
February 9, 2022 at 7:11 am #2110721Ema
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
EFebruary 9, 2022 at 7:42 am #2110756David
StaffCustomer Support1. 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_loopHope 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 .
February 9, 2022 at 9:37 am #2111054Ema
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 EFebruary 9, 2022 at 9:39 am #2111058David
StaffCustomer SupportAwesome – let me know how you get on with it 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.