WordPress 테마에 댓글 작성 시 표시되는 콘텐츠 도구 추가
6,355 1
때때로 우리는 가치 있는 글을 작성한 후, 수고한 노력을 보호하거나 무작정 가져가는 사람들에게 조금의 기회도 주지 않기 위해, 또는 댓글 수를 늘리기 위해 댓글 작성 시 콘텐츠가 표시되는 기능을 사용하고 싶을 때가 있습니다. 저는 지경조(知更鸟)의 댓글 작성 시 표시 기능을 참고한 다음, 해당 코드를 독립적으로 분리했습니다. 아래에서 여러분과 공유하겠습니다.
코드
PHP 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 = "xinyewl@qq.com";
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');
코드의 xinyewl@qq.com을 자신의 관리자 이메일로 변경하면 해당 이메일 사용자가 콘텐츠를 바로 볼 수 있습니다.
위 코드를 테마 디렉터리 아래의 functions.php에 넣으면 사용할 수 있습니다.
호출 방법
비주얼 편집기 또는 편집 상자에 단축 코드 [reply]숨겨진 콘텐츠[/reply]를 입력하고, 중간 부분을 숨기려는 콘텐츠로 변경하면 됩니다.

댓글
(1)没用啊,还是现实隐藏内容