- This topic has 9 replies, 4 voices, and was last updated 4 years, 7 months ago by
Elvin.
-
AuthorPosts
-
October 5, 2021 at 7:57 am #1953538
TWMA Support
Hi Team
Looking to include a grid of the latest 3 posts (of a custom post type) within the post content area at he bottom of the content. Basically left is header, content,latest 3 posts, footer and the right would be header, sidebar, footer. So I am assuming that I would need to fetch the latest 3 posts (to be displayed in a block in a row) and include this fetch php code in teh single.php file.
Please advise how best to do this so that person creating a post doesnt need to worry about incliuding and building out structure each time a post is created.
Hope I am making sense.
Thanks
October 5, 2021 at 8:37 am #1953594David
StaffCustomer SupportHi there,
is this to be displayed on all posts ? And will the list contain the latest posts or will it be related to the single post ( eg. by Taxonomy Term ). Let me know and i can give some pointers.
October 5, 2021 at 11:26 am #1953795TWMA Support
Hi hi
Yes all posts and if I can show latest posts from the same post category that would be great.
Thanks
October 5, 2021 at 11:46 am #1953817Leo
StaffCustomer SupportYou can consider using one of these plugins:
https://wordpress.org/plugins/wp-show-posts/
https://en-ca.wordpress.org/plugins/contextual-related-posts/And insert the plugin shortcode using a hook element:
https://docs.generatepress.com/article/hooks-visual-guide/
https://docs.generatepress.com/article/hooks-element-overview/October 5, 2021 at 12:01 pm #1953828TWMA Support
Thanks Leo
Looking for some pho I can add to the theme file so the person adding the post doesn’t need to add shortcodes.
Is that possible? I have a custom post single theme file setup in the GeneratePress child theme.
Thanks
October 5, 2021 at 12:28 pm #1953853Leo
StaffCustomer SupportLooking for some pho I can add to the theme file
That’s not possible without a custom solution unfortunately.
so the person adding the post doesn’t need to add shortcodes.
If you use the hook method I suggested then set the display rules to all single posts then it will be automatically added to all single posts.
WordPress offers a core latest posts block now so you can also consider that:
https://wordpress.org/support/article/latest-posts-block/But it doesn’t offer a lot of options.
October 5, 2021 at 4:44 pm #1954029TWMA Support
Hi Leo
Thanks. I have installed the Show Posts plugin and see that it has a php string and a shortcode, which is useful. However when I put the php string into my template (now casks used to be single.php), nothing shows up (see below…hope I have added the code correctly)…
Thanks
<div id="primary" <?php generate_do_element_classes( 'content' ); ?>> <main id="main" <?php generate_do_element_classes( 'main' ); ?>> <?php /** * generate_before_main_content hook. * * @since 0.1 */ do_action( 'generate_before_main_content' ); if ( generate_has_default_loop() ) { while ( have_posts() ) : the_post(); generate_do_template_part( 'casks' ); endwhile; } if ( function_exists( 'wpsp_display' ) ) wpsp_display( 600 ); /** * generate_after_main_content hook. * * @since 0.1 */ do_action( 'generate_after_main_content' ); ?> </main> </div>October 5, 2021 at 8:31 pm #1954130Elvin
StaffCustomer SupportHi there,
I’m not exactly sure that’s the best way of adding it.
Any particular reason why you have to add it this way? Also, can you verify if the ID within wpsp_display is correct?
Consider using a Hook element instead.
Place the shortcode on a Hook element and set its hook to
generate_after_main_content. Set the display rule location to the page you want this to apply on.October 14, 2021 at 3:05 pm #1963785TWMA Support
Hi
Thanks Elvin. Took you advice and used a hook. Worked a treat. Thanks again.
October 14, 2021 at 5:25 pm #1963855Elvin
StaffCustomer SupportNo problem. 😀
-
AuthorPosts
- You must be logged in to reply to this topic.