Recent Posts- where to add the code?

Hello!

I was interested in putting recent posts on my blogs, and I stumbled upon this: http://demo.theme.co/integrity-1/shortcodes/recent-posts/

I want to add this code: [recent_posts count=“2”] but I don’t know if I have to do that at the end of each blog post or in the CSS?

Thanks for your help!
-Nadia

Hi Nadia,

It should be related to the answer from your post here:

But, instead of just having:

// Author Bio below the post content - Single page only.
// =============================================================================

add_action( "x_after_the_content_end", "add_post_shortcode" );

function add_post_shortcode() {
    if( is_singular( 'post' ) ){
        echo do_shortcode('[author title="About the Author"]');
    }
}
// =============================================================================

Please update it to:

// Author Bio below the post content - Single page only.
// =============================================================================

add_action( "x_after_the_content_end", "add_post_shortcode" );

function add_post_shortcode() {
    if( is_singular( 'post' ) ){
        echo do_shortcode('[author title="About the Author"]');
        echo '<h2>Recent Posts</h2>';
        echo do_shortcode('[recent_posts count="3"]');
    }
}
// =============================================================================

Hope this helps.

Sorry, that reply was confusing to me…

I want to add this to the bottom of all my blog posts, except I don’t want to have to do it manually every time.

Thank you for your help!

  • Nadia

Hello Nadia,

Thanks for updating the thread.

Later part of the code that my colleague @Jade shared will automatically recent post in a count of 3 posts. Please add the code into your child theme function.php file. If you have already added the code to display author information, please replace that with the one Jade shared in later part of the reply.

Thanks.

Oh ok, thanks for the clarification.

If I don’t want to add the author information just yet, would the following code be correct (for the Recent Posts section only)?

// Recent Posts below the post content - Single page only.
// =============================================================================

add_action( "x_after_the_content_end", "add_post_shortcode" );

function add_post_shortcode() {
    if( is_singular( 'post' ) ){
        echo '<h2>Recent Posts</h2>';
        echo do_shortcode('[recent_posts count="2"]');
    }
}
// =============================================================================

Thanks!

Hey Nadia,

Yes, that is the code that you need to add the recent post items.

Regards.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.