Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

share|improve this question
    
"25% accept rate" –  kaiser Jun 7 '11 at 17:15
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
add comment

1 Answer 1

up vote 1 down vote accepted

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 />';
    }
}
share|improve this answer
    
Thanks Kaiser, works like a charm :) –  FLX Jun 8 '11 at 9:42
    
@FLX You're welcome :) –  kaiser Jun 8 '11 at 10:11
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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