且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Wordpress上显示登录的用户评论(仅)

更新时间:2023-11-30 17:50:10


  1. 点击设置> 讨论,然后从中设置所需内容。有一种选项仅允许已注册成员发布评论。

  2. http:// pastebin.com/EJcghXAW -请参见第39行的代码,在您的情况下也应使用相同的方法。

  1. Click on Settings > Discussions and set what you want from there. There is one option that lets only registered members to post a comment.
  2. http://pastebin.com/EJcghXAW - see code from line #39, same aproach also in your case.

查询注释是正常的wordpress方法,但是您需要将其包括在上面链接和指向的条件中。

The query for the comments is the normal wordpress way, but you need to include it in the conditionals linked and pointed above.

用法示例:

<?php
if ( is_user_logged_in() ) {
    $user_id = get_current_user_id();
    $args = array(
        'status' => 'approve',
        'order' =>  'DESC',
        'user_id' => $user_id
    );
    $comments = get_comments($args);
    foreach($comments as $comment) :
        echo '<p>'; 
        echo($comment->comment_author . '<br />' . $comment->comment_content);
        echo '</p>';
    endforeach;
}
?>