Web Development & WordPress

How to Display Latest Blog Posts at the End of Each Post in Smart Theme v3 (OptimizePress Guide)

Smart Theme V3 by Optimizepress

If you are using Smart Theme v3 by OptimizePress, you may have noticed that there is no built-in option to automatically show your latest blog posts at the end of every article.

In this guide, I will show you exactly how to add a “Latest Articles” section at the bottom of each blog post using a simple PHP function.
No plugin is required (except Code Snippets if you don’t use a child theme).

This is the result you will get:

Smart Theme V3 by Optimizepress

Why This Works in Smart Theme v3

Smart Theme v3 includes a special hook called:

op_single_after_content

We will use this hook to display 2 of your most recent posts automatically under every single post.

Step-by-Step: Add Latest Blog Posts Below Each Post

You can use either:

Here is the full code:

// Define a function to display latest articles
function display_latest_articles() {
    $args = array(
        'post_type'      => 'post',
        'posts_per_page' => 2,
        'orderby'        => 'date',
        'order'          => 'DESC',
    );

    $latest_posts = new WP_Query( $args );

    if ( $latest_posts->have_posts() ) :
        ?>
        <aside class="op-related-articles show">
            <hr>
            <h4 class="op-related-articles-titlea" style="text-align:center;">Latest Articles</h4>
            <div class="op-related-articles-grid-row op-related-articles-grid-row--2-col">
                <?php while ( $latest_posts->have_posts() ) : $latest_posts->the_post(); ?>
                    <div class="box-item">
                        <div class="post-box">
                            <a class="op-related-articles-img-container" href="<?php the_permalink(); ?>">
                                <span class="visuallyhidden"><?php the_title(); ?></span>
                                <?php the_post_thumbnail( 'related-article-size', array( 'class' => 'attachment-related-article-size size-related-article-size wp-post-image', 'loading' => 'lazy' ) ); ?>
                            </a>
                            <div class="post-box-description">
                                <h3 class="op-related-articles-headline"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
                            </div>
                        </div>
                    </div>
                <?php endwhile; ?>
            </div>
        </aside>
        <?php
        wp_reset_postdata(); // Reset post data
    endif;
}

// Hook into op_single_after_content to display latest articles
add_action('op_single_after_content', 'display_latest_articles', 50);

How the Code Works

  • It fetches 2 latest posts using WP_Query
  • Displays the post thumbnail + title
  • Wraps them inside a responsive OptimizePress grid
  • Uses the theme hook so the section appears right after your post content

You can increase the number of posts by changing:

'posts_per_page' => 2,

Leave a comment