如何在Wordpress上显示登录的用户评论(仅) [英] How to display logged in users comments (only) on Wordpress

查看:215
本文介绍了如何在Wordpress上显示登录的用户评论(仅)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用wordpress建立一个小众问答网站,用户可以使用该网站登录并发布问题,或者登录并回答问题。

I'm currently building a niche Q+A site using wordpress with which users can either log in and post questions or log in and answer questions.

问题是当前存储为帖子,答案存储为评论。我希望答疑者能够登录并在一个页面上查看所有评论(答案),并带有指向原始帖子(问题)的链接。

Questions are currently being stored as posts, and answers stored as comments. I want question answerers to be able to log in and view all their comments (answers) on one page with a link to the original post (question).

我可以通过这种方式轻松列出帖子(即在一页上列出所有已登录用户的帖子,即他们的原始问题),但似乎无法通过评论来做到这一点(即在一页上列出所有已登录用户的答案。)有什么方法可以做到这一点?

I can easily list posts in this way (i.e. list all of the logged in users posts on one page i.e. their original questions) but cant seem to do this with comments (i.e. list all the logged in user's answers on one page.) Is there any way to do this?

推荐答案


  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;
}
?>

这篇关于如何在Wordpress上显示登录的用户评论(仅)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆