本文實(shí)例講述了WordPress后臺(tái)顯示相關(guān)用戶文章相關(guān)聯(lián)評(píng)論的方法。分享給大家供大家參考。具體分析如下:
將下面的代碼添加到當(dāng)前主題的 functions.php 文件即可,代碼如下:
復(fù)制代碼
代碼如下://后臺(tái)只顯示當(dāng)前用戶文章關(guān)聯(lián)的評(píng)論
function wpdx_get_comment_list_by_user($clauses) {
if (is_admin()) {
global $user_ID, $wpdb;
$clauses['join'] = ", wp_posts";
$clauses['where'] .= " AND wp_posts.post_author = ".$user_ID." AND wp_comments.comment_post_ID = wp_posts.ID";
};
return $clauses;
};
if(!current_user_can('edit_others_posts')) {
add_filter('comments_clauses', 'wpdx_get_comment_list_by_user');
}
function wpdx_get_comment_list_by_user($clauses) {
if (is_admin()) {
global $user_ID, $wpdb;
$clauses['join'] = ", wp_posts";
$clauses['where'] .= " AND wp_posts.post_author = ".$user_ID." AND wp_comments.comment_post_ID = wp_posts.ID";
};
return $clauses;
};
if(!current_user_can('edit_others_posts')) {
add_filter('comments_clauses', 'wpdx_get_comment_list_by_user');
}
注:如果你的WordPress所使用的數(shù)據(jù)庫(kù)前綴不是默認(rèn)的 wp_,請(qǐng)將第 5 、6 行中的 wp_ 修改為你的WordPress站點(diǎn)的數(shù)據(jù)庫(kù)前綴.
希望本文所述對(duì)大家的WordPress建站有所幫助。
【網(wǎng)站聲明】本站除付費(fèi)源碼經(jīng)過(guò)測(cè)試外,其他素材未做測(cè)試,不保證完整性,網(wǎng)站上部分源碼僅限學(xué)習(xí)交流,請(qǐng)勿用于商業(yè)用途。如損害你的權(quán)益請(qǐng)聯(lián)系客服QQ:2655101040 給予處理,謝謝支持。