Show User's Comments on Author Page
-
[ Please do not post support topics in the Your WordPress sub-forum. Moving topic to How-To and Troubleshooting. ]
Hello dears,
I saw some questions about showing comments for a particular user, and those topic did not gain a desired result. But I’ve figured out how it is possible to show user’s comment on Auhtor Page.You just need to put this code on your author.php file :
<?php $args = array( 'user_id' => $author, // use user_id ); $comments = get_comments($args); foreach($comments as $comment) : echo($comment->comment_author . '<br />' . $comment->comment_content); endforeach; ?>
It will show all comments for a specific user on Author Page.
I have a sample author.php template which could be useful for you :
<?php get_header(); ?> <div id="content" class="narrowcolumn"> <!-- This sets the $curauth variable --> <?php $curauth = (isset($_GET['author_name'])) ? get_user_by('slug', $author_name) : get_userdata(intval($author)); ?> <h2>About: <?php echo $curauth->nickname; ?></h2> <dl> <dt>Website</dt> <dd><a href="<?php echo $curauth->user_url; ?>"><?php echo $curauth->user_url; ?></a></dd> <dt>Profile</dt> <dd><?php echo $curauth->user_description; ?></dd> </dl> <h2>Posts by <?php echo $curauth->nickname; ?>:</h2> <ul> <!-- The Loop --> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <li> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link: <?php the_title(); ?>"> <?php the_title(); ?></a>, <?php the_time('d M Y'); ?> in <?php the_category('&');?> </li> <?php endwhile; else: ?> <p><?php _e('No posts by this author.'); ?></p> <?php endif; ?> <!-- End Loop --> </ul> <h2>Comments by <?php echo $curauth->nickname; ?>:</h2> <?php $args = array( 'user_id' => $author, // use user_id ); $comments = get_comments($args); foreach($comments as $comment) : echo($comment->comment_author . '<br />' . $comment->comment_content); endforeach; ?> </div> <?php get_sidebar(); ?> <?php get_footer(); ?>
- The topic ‘Show User's Comments on Author Page’ is closed to new replies.