Displaying Author-Specific Posts in WordPress

0

Running a successful blog requires maintaining the interest of your readers continuously. One effective way to achieve this is by providing them with customized content through author-specific related posts. By compiling and offering a specific author’s posts, readers can easily find and enjoy more articles from their favorite authors, leading them to stay longer on the blog. This article will cover how to display author-specific related posts using WordPress and discuss its importance.

unsplash

1. Importance of Displaying Author-Specific Related Posts

Reasons for Offering a Specific Author’s Posts

When multiple authors contribute to a blog, readers may prefer the writings of specific authors. Compiling and providing a specific author’s posts can increase reader satisfaction. This encourages readers to stay longer on the blog, thereby increasing dwell time and positively impacting SEO scores.

Providing Customized Content for Readers

Readers often want to read more from their favorite authors. By offering author-specific related posts, you can provide customized content to readers. This increases reader engagement and helps boost overall blog traffic.

2. How to Display Author-Specific Related Posts

Displaying Author-Specific Related Posts in WordPress

To display author-specific related posts in WordPress, you can use WP_Query to create a custom query. Below is an example code for displaying a specific author’s related posts.

Example Code

1. Adding Function to functions.php
<?php
function set_custom_related_posts($limit, $author_id = null)
{
    ?>
    <div class="recomded_list related_posts">
        <h3 class="list_title">Related Posts</h3>
        <?php
        global $post;

        $relatedArgs = array(
            'posts_per_page'   => $limit, // Number of items to display
            'post__not_in'     => array(get_the_ID()), // Exclude the current post
            'no_found_rows'    => true, // Speed up the query
            'orderby'          => 'rand', // Randomly display
            'category__not_in' => array(
                get_cat_ID('Investment Interest Items'),
                get_cat_ID('Investment Ideas'),
                get_cat_ID('Business Checklists'),
                get_cat_ID('Success Checklists'),
                get_cat_ID('Investment Checklists')
            ) // Exclude categories
        );

        if ($author_id) {
            $relatedArgs['author'] = $author_id; // Query only specific author's posts
        }

        $relateds = wp_get_post_tags($post->ID);
        if ($relateds) {
            $tag_ids = array();
            foreach ($relateds as $wpex_related_tag) {
                $tag_ids[] = $wpex_related_tag->term_id;
            }
            if (!empty($tag_ids)) {
                $relatedArgs['tag__in'] = $tag_ids;
            }
        } else {
            $relateds = wp_get_post_terms(get_the_ID(), 'category');
            $cats_ids = array();
            foreach ($relateds as $wpex_related_cat) {
                $cats_ids[] = $wpex_related_cat->term_id;
            }
            if (!empty($cats_ids)) {
                $relatedArgs['category__in'] = $cats_ids;
            }
        }

        // Query posts
        $wpex_query = new WP_Query($relatedArgs);

        if ($wpex_query->have_posts()) {
            // Loop through posts
            while ($wpex_query->have_posts()) : $wpex_query->the_post(); ?>

                <div class="post_item">
                    <div class="post_thumb">
                        <a rel="nofollow" href="<?php the_permalink(); ?>">
                            <?php
                            $getPostThumbUrl = get_field('set_custom_thumbnail') ? home_url() . get_field('set_custom_thumbnail') : get_the_post_thumbnail_url(get_the_ID(), 'full');
                            echo '<img src="' . esc_url($getPostThumbUrl) . '" alt="' . esc_attr(get_the_title()) . '" />';
                            ?>
                        </a>
                    </div>
                    <div class="post_header">
                        <h3 class="post_title"><a rel="nofollow" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
                        <div class="post_meta">
                            <div class="post_date"><?php echo get_the_date(); ?></div>
                            <div class="post_author"><?php the_author_posts_link(); ?></div>
                        </div>
                    </div>
                </div>

            <?php endwhile;
        } else {
            echo '<div class="no_search_post">No related posts found.</div>';
        }

        // Reset post data
        wp_reset_postdata();
        ?>
    </div>
    <?php
}
?>
2. Calling the Function in a Template File

To display author-specific related posts, call the function in a template file. For example, you can add the following in the sidebar.php file.

<?php
// Display related posts using the author's ID
$author_id = get_the_author_meta('ID');
set_custom_related_posts(5, $author_id);
?>

3. Effects of Displaying Related Posts

Increase Reader Engagement

By providing author-specific related posts, readers can easily find and read more articles from their favorite authors. This significantly boosts reader satisfaction and helps increase the blog’s dwell time.

Positive Impact on SEO

Effective management of related posts can also positively impact the blog’s SEO. Related posts improve the internal linking structure, making it easier for search engines to understand the blog’s content. This helps in improving the blog’s ranking on search engine results pages.

unsplash

Conclusion

Displaying author-specific related posts is an effective way to provide customized content to readers. This not only enhances reader satisfaction and increases dwell time but also positively impacts the blog’s SEO, helping it rank higher on search engine results pages. By employing this strategy, blog operators can successfully grow their blogs.

Leave a Reply