0

I've based a lot of my method on this thread here

I can currently display 5 latest comments on an author template page. I want to display the latest 3 replies from any user for each 'main' comment (hence parent=0)

I can recognise the replies through print_r but using for example get_comment_link for the comment_id is a complete no show and recognises no replies.

Here's the code.

    <?php $args = array(
        'user_id' => $curauth->ID,
                    'number' => 5,
                    'status' => 'approve',
                    'parent' => 0
                    );
$comments = get_comments($args);
   if ( $comments )
    {
foreach($comments as $c){
    echo '<ul id="authorcomments">';
    echo '<li>';
    echo '<a id="authorcommentlink" href="'.get_comment_link( $c->comment_ID ).'"> ';
    echo get_the_title($c->comment_post_ID);
    echo '</a>';
    echo "</br> <div id='authorcommentexcerpt'>" .  get_comment_excerpt( $c->comment_ID );
    echo "</div></li>\n";
    echo '</ul>';

    $parent_comment_id = $c->comment_ID;
    $comment_meta_args = array(
                               'status' => 'approve',
                               'parent' => intval($parent_comment_id),
                               'number' => 3
                               );
    $replies = get_comments($comment_meta_args);
    echo '<ul id="authorcomments">';
    echo '<li>';
    echo '<a id="authorcommentlink" href="'.get_comment_link( $replies->comment_ID ).'"> ';
    echo get_the_title($replies->comment_post_ID);
    echo '</a>';
    echo "</br> <div id='authorcommentexcerpt'>" .  get_comment_excerpt( $replies->comment_ID );
    echo "</div></li>\n";
    echo '</ul>';
}

} else { echo "<p style='text-align: center'> Nothing! </p>\n";} ?>
0

My bad. Should have added a foreach for the replies as well.

 <?php $args = array(
        'user_id' => $curauth->ID,
                  'number' => 5,
                'status' => 'approve',
                'parent' => 0
                );
 $comments = get_comments($args);
    if ( $comments )
 {
foreach($comments as $c){
echo '<ul id="authorcomments">';
echo '<li>';
echo '<a id="authorcommentlink" href="'.get_comment_link( $c->comment_ID ).'"> ';
echo get_the_title($c->comment_post_ID);
echo '</a>';
echo "</br> <div id='authorcommentexcerpt'>" .  get_comment_excerpt( $c->comment_ID );
echo "</div></li>\n";
echo '</ul>';


$parent_comment_id = $c->comment_ID;
$comment_meta_args = array(
                           'status' => 'approve',
                           'parent' => intval($parent_comment_id),
                           'number' => 3
                           );
$replies = get_comments($comment_meta_args);
foreach($replies as $r) {
echo '<ul id="authorcomments2">';
echo '<li>';
echo '<a id="authorcommentlink2" href="'.get_comment_link( $r->comment_ID ).'"> ';
echo get_the_title($r->comment_post_ID);
echo '</a>';
echo "</br> <div id='authorcommentexcerpt2'>" .  get_comment_excerpt( $r->comment_ID );
echo "</div></li>\n";
echo '</ul>';
}

}




 } else { echo "<p style='text-align: center'> Nothing! </p>\n";} ?>
| improve this answer | |

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.