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

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

问题描述

我目前正在使用wordpress创建一个利基Q + A网站,用户可以登录并提出问题或登录并回答问题。



问题当前存储为帖子,答案存储为注释。我想让问答回答者能够在一个页面上登录并查看他们的所有评论(答案),并提供指向原始帖子(问题)的链接。



我可以轻松地以这种方式列出帖子(即列出所有登录的用户在一个页面上发布的帖子,即他们原来的问题),但似乎不能用注释有没有办法做到这一点?



非常感谢您的帮助,这是驱动我疯了!

解决方案


  1. 点击 em>并设置你想要的。有一个选项只允许注册会员发布评论。

  2. http:// pastebin.com/EJcghXAW - see line from line#39,same aproach also in your case。

查询

使用示例:

>

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


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 loged in user's answers on one page.) Is there any way to do this?

Many thanks for your help, this is driving me mad!!!!

解决方案

  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.

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

Usage example:

<?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上显示loged的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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