WordPress.org

Ready to get started?Download WordPress

Forums

How to display link to parent comment in threaded comments (3 posts)

  1. jhayrocas
    Member
    Posted 3 years ago #

    Hi,

    I want to display the link to the parent comment in the header of comments made in reply to another when comment threading is enabled.

    WordPress 3.0+ supports this according to the documentation about comments which says:

    Change to comments UI to show when a comment is replying to another, and link to the parent comment

    What does that mean exactly? And how can I do that?

    Thanks!

  2. Joseph
    Member
    Posted 3 years ago #

    The doc is referring to the comment UI in the dashboard.

    Try the following:

    if ( $comment->comment_parent ) {
    	$parent = get_comment( $comment->comment_parent );
    	$parent_link = esc_url( get_comment_link( $comment->comment_parent ) );
    	printf( 'In reply to <a href="%1$s">%2$s</a>.', $parent_link, $parent->comment_author );
    }

    Ref: /wp-admin/includes/template.php Ln:2065

  3. jhayrocas
    Member
    Posted 3 years ago #

    Thanks Joseph,

    The code you gave didn't work, but tweaked it a little and here's the one that got working on my blog:

    global $comment;
        if ($comment->comment_parent) {
            $parent_comment = get_comment($comment->comment_parent);
            echo 'in reply to <a>comment_ID, array('get_page_of_comment' => true)))).'">'.$parent_comment->comment_author.'</a>';
        }

Topic Closed

This topic has been closed to new replies.

About this Topic