Site logo

Archived topic

Include a post grid of latest posts at bottom of post content area

9 replies · Started by TWMA Support on October 5, 2021

Viewing posts 1–10 of 10

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

Hi 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.

Hi hi

Yes all posts and if I can show latest posts from the same post category that would be great.

Thanks

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

Looking 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.

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>

Hi 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.

Hi

Thanks Elvin. Took you advice and used a hook. Worked a treat. Thanks again.

No problem. :D

This archived topic is closed to new replies.