1

I'm creating an author.php page and I'd like to show comments as well as posts from a custom post type. I already have the list of posts but I'm looking into an efficient way of displaying the most recent comments from that author as well. So far I haven't found anything except widget and bloated plugins.

I'd like to do that particularly in one stream (posts/comments) but I can understand if this is too challenging :)

Thanks! Dennis

  • 1
    Thanks for bringing this to my attention, I'll make sure to mark my posts next time. – FLX Jun 8 '11 at 8:36
1

This function calls all comments by an author and strips every comment to a max-length. Adjust the comment excerpt length when calling the function in your template like wpse19316_author_comments( 100 );.

function wpse19316_author_comments( $length )
{
    $final_length = (int) $length;
    $author_comments = get_comments( array( 'ID' => $GLOBALS['authordata']->ID ) );
    foreach ( $author_comments as $comment )
    {
        $comment_length = sublen( $comment->comment_content );
        $comment_excerpt = $comment->comment_content;
        if ( $comment_length > $final_length )
            $comment_excerpt = substr( $comment->comment_content, $final_length );
        echo $comment_excerpt.'<br />';
    }
}
  • I am trying to get your function to work properly in our WP installation. I add the code above that you mentioned to the functions.php as cited below with standard php tags around it. And that tried to use <?php wpse19316_author_comments() ?> to display the output to an author page for a particular user on the author.php. Am I doing it right or is there something I'm missing? If you can help I would be so happy. Thanks in advance. – user9964 Nov 3 '11 at 13:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.