2013-03-12 72 views
1

我有一个WordPress的网站,我已经建立了一个author.php页面显示用户信息。查看作者对author.php的最新评论

目前我设法让它显示作者使用query_posts添加到网站的最新帖子。

但是,我希望这个页面也显示作者最新的评论,他发布在网站上,但我似乎无法弄清楚如何使用查询来做到这一点,因为我不确定Wordpress是否支持此功能。

+0

发表您的表的模式。 – 2013-03-12 16:49:58

+0

你能否详细说明请问JW? – 2013-03-12 16:57:48

+0

评论是保存在数据库中的权利?我希望你发布重要的表格,以便我们可以帮助你建立查询。 – 2013-03-12 16:59:18

回答

0

有这个功能:get_comments

用法示例(基于食品为例):

$auth_id = get_the_author_meta('ID'); 
$defaults = array(
    'author_email' => '', 
    'ID' => '', 
    'karma' => '', 
    'number' => '', 
    'offset' => '', 
    'orderby' => '', 
    'order' => 'DESC', 
    'parent' => '', 
    'post_ID' => '', 
    'post_id' => 0, 
    'post_author' => '', 
    'post_name' => '', 
    'post_parent' => '', 
    'post_status' => '', 
    'post_type' => '', 
    'status' => '', 
    'type' => '', 
    'user_id' => $auth_id, 
    'search' => '', 
    'count' => false, 
    'meta_key' => '', 
    'meta_value' => '', 
    'meta_query' => '', 
); 
$auth_comments = get_comments($defaults); 
var_dump($auth_comments); 

重要提示:忌用query_posts,请参阅:When should you use WP_Query vs query_posts() vs get_posts()?

+0

感谢Brasofilo,这无疑指向了我正确的方向。如果我想要显示当前作者的评论,如果他发布了评论并显示一条默认消息,例如:此用户尚未发布任何评论 - 如果他没有发布评论。使用if else语句,完整的代码是什么? – 2013-03-14 12:39:56