如何按登录用户和回复显示评论?

时间:2013-05-22 作者:mackanL

我想创建一个个人资料页面并显示登录人员的评论。以及对其评论的回应。

像这样:

Post title

注释(按登录用户)

--->对其评论的回应(回复)

有什么办法吗?

EDIT:

这就是我现在得到的。我在我拥有的页面上使用一个短代码来获取登录者的评论。

What I want to get is also the responses for each comment made by this logged in user.

<?php
/*
Plugin Name: Show Recent Comments by a particular user
Plugin URI: http://blog.ashfame.com/?p=876
Description: Provides a shortcode which you can use to show recent comments by a particular user
Author: Ashfame
Author URI: http://blog.ashfame.com/
License: GPL
Usage: 
*/

add_shortcode ( \'show_recent_comments\', \'show_recent_comments_handler\' );

function show_recent_comments_handler( $atts, $content = null )
{
    extract( shortcode_atts( array( 
        "count" => 10,
        "pretty_permalink" => 0
        ), $atts ));

    $output = \'\'; // this holds the output

    if ( is_user_logged_in() )
    {
        global $current_user;
        get_currentuserinfo();

        $args = array(
            \'user_id\' => $current_user->ID,
            \'number\' => $count, // how many comments to retrieve
            \'status\' => \'approve\'
            );

        $comments = get_comments( $args );
        if ( $comments )
        {
            $output.= "<ul>\\n";
            foreach ( $comments as $c )
            {
            $output.= \'<li>\';
            if ( $pretty_permalink ) // uses a lot more queries (not recommended)
                $output.= \'<a href="\'.get_comment_link( $c->comment_ID ).\'">\';
            else
                $output.= \'<a href="\'.get_settings(\'siteurl\').\'/?p=\'.$c->comment_post_ID.\'#comment-\'.$c->comment_ID.\'">\';           
            $output.= $c->comment_content;
            $output.= \'</a>\';
            $output.= "</li>\\n";
            }
            $output.= \'</ul>\';
        }
    }
    else
    {
        $output.= "<h2>You should be logged in to see your comments. Make sense?</h2>";
        $output.= \'<h2><a href="\'.get_settings(\'siteurl\').\'/wp-login.php?redirect_to=\'.get_permalink().\'">Login Now &rarr;</a></h2>\';
    }
    return $output;
}
?>

1 个回复
SO网友:mackanL

有什么想法吗?

我尝试运行相同的数组和foreach,但要测试user\\u id=>1。但我得到的只是一个完整的列表,上面有id为1的用户的评论。

我只想显示当前用户注释下方的响应(来自用户id 1)。

结束

相关推荐

<?php wp_list_Comments();?>是否可以将完整代码放在Comments.php页面中

我强烈需要编辑用户留下的评论的一些部分,我想添加到评论作者的链接。php页面,如果他/她是注册用户,请在他/她的名字旁边放置文本链接。我有这个密码<?php wp_list_comments(); ?> 但我想知道是否有可能用完整的代码代替注释中的代码。phpThanks!