看到很多seo博客有設置隱藏內容,想要查看隱藏內容必須評論才能獲得查看權限,感覺這個功能蠻好的,今天給大家分享一下wordpress設置評論后查看隱藏內容權限的方法!
通過簡碼實現部分內容評論后可見
1、將下面的代碼添加到主題的 functions.php 文件:
function reply_to_read($atts, $content=null) {
extract(shortcode_atts(array("notice" => '<p class="reply-to-read">溫馨提示: 此處內容需要<a href="#respond" title="評論本文">評論本文</a>后才能查看.</p>'), $atts));
$email = null;
$user_ID = (int) wp_get_current_user()->ID;
if ($user_ID > 0) {
$email = get_userdata($user_ID)->user_email;
//對博主直接顯示內容
$admin_email = "xxx@aaa.com"; //博主Email
if ($email == $admin_email) {
return $content;
}
} else if (isset($_COOKIE['comment_author_email_' . COOKIEHASH])) {
$email = str_replace('%40', '@', $_COOKIE['comment_author_email_' . COOKIEHASH]);
} else {
return $notice;
}
if (empty($email)) {
return $notice;
}
global $wpdb;
$post_id = get_the_ID();
$query = "SELECT `comment_ID` FROM {$wpdb->comments} WHERE `comment_post_ID`={$post_id} and `comment_approved`='1' and `comment_author_email`='{$email}' LIMIT 1";
if ($wpdb->get_results($query)) {
return do_shortcode($content);
} else {
return $notice;
}
}
add_shortcode('reply', 'reply_to_read');
注:請自行修改第8行的郵件為管理員的。如果你的網站使用了ajax免刷新提交評論,你可能需要修改第2行的提示文字,提示訪客評論后刷新頁面來查看隱藏內容。
2.編輯文章時,使用下面的簡碼:
【reply】評論可見的內容【/reply】
或者
?【reply notice="自定義的提示信息"】評論可見的內容【/reply】
使用時,請將【 】改為[ ]
該方法最初應該來自“亂了感覺” ,后來不知誰改進了功能,添加“對管理員不隱藏”的判斷。文章內容來自Wordpress大學,一個很好的wordpress學習的站點,更多內容大家可以異步至Wordpress大學!
知道怎么設置評論后查看隱藏內容權限了嗎?趕緊試試吧!測試頁面:利用高權重政府網站發布錨文本虛擬外鏈技術
原創文章"wordpress怎么設置評論后查看隱藏內容權限”轉載請注明出處:http://www.dalciva.com/725.html