2013-03-12 66 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