在wordpress 中不使用插件来实现评论后才可以查看!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
////回复可见///// function reply($content){ if (preg_match_all('/<!--reply start-->([\s\S]*?)<!--reply end-->/i', $content, $hide_words)){ $stats = 'hide'; global $current_user; get_currentuserinfo(); if ($current_user->ID) { $email = $current_user->user_email; } else if (isset($_COOKIE['comment_author_email_'.COOKIEHASH])) { $email = $_COOKIE['comment_author_email_'.COOKIEHASH]; } $ereg = "^[_\.a-z0-9]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,5}$"; if (eregi($ereg, $email)) { global $wpdb; global $id; $comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_author_email = '".$email."' and comment_post_id='".$id."'and comment_approved = '1'"); if ($comments) { $stats = 'show'; } } $admin_email = "admin@chrafz.com"; //博主Email,博主直接查看 if ($email == $admin_email) { $stats = 'show'; } $hide_notice = '<div style="text-align:center;border:1px dashed #FF9A9A;padding:8px;margin:10px auto;color:#FF6666;">温馨提示:此处内容需要<a href="'. get_permalink().'#respond" title="评论本文">评论本文</a>后,<a href="javascript:window.location.reload();" title="刷新">刷新本页</a>才能查看。</div>'; if( $stats == 'show' ){ $content = str_replace($hide_words[0], $hide_words[1], $content); }else{ $content = str_replace($hide_words[0], $hide_notice, $content); } } return $content; } add_filter('the_content', 'reply'); |
将上面的代码黏贴到function.php里
发表文章,在你想要隐藏的某部分内容中加入<!–reply start–>你要隐藏的内容<!–reply end–>(注:在代码模式加入)
评论抢沙发