添加代碼
將下面的代碼添加到主題的 functions.php 文件:
//部分內容評論可見
function reply_to_read($atts, $content = null) {
extract(shortcode_atts(array("notice" => '<blockquote><center><p class="reply-to-read" style="color: blue;">注意:本段內容須成功“<a href="' . get_permalink() . '#respond" title="回覆本文">回覆本文</a>”後“<a href="javascript:window.location.reload();" title="刷新本頁">刷新本頁</a>”方可查看!</p></center></blockquote>') , $atts));
$email = null;
$user_ID = (int)wp_get_current_user()->ID;if ($user_ID > 0) {
$email = get_userdata($user_ID)->user_email;//對博主直接顯示內容
$admin_email = get_bloginfo('admin_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');
調用方法
編輯文章時,使用下面的兩種簡碼調用:
刪除第一個reply的空格,把斜槓替換爲/
注意:此方法對QQ快速登錄的用戶是無效的。
//簡碼1 任選一種使用
[ reply]評論可見的內容[斜槓reply]
//簡碼2 任選一種使用
[ reply notice="自定義的提示信息"]評論可見的內容[斜槓reply]