纯代码实现wordpress文章隐藏内容评论可见
生活随笔
收集整理的這篇文章主要介紹了
纯代码实现wordpress文章隐藏内容评论可见
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
在很多網站上都看過這個效果,比如說知己知彼網站,他的部分資源是需要我們評論后才能下載的,那么這個到底有什么用呢,對我而言,除了拿來裝逼,還可以增加我的評論數量,不多說,先看看效果:
其實WordPress有很多的插件可以實現這個功能,比如說Easy2Hide,但是插件當然是越少越好,下面我就來說說怎么用代碼實現這個功能:
| 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 | function reply_to_read($atts, $content=null) { ????extract(shortcode_atts(array("notice" => '<p class="reply-to-read" style="border-width: 1px 1px 1px 1px;border-color: #F2F2F2;line-height: 150%;"><blockquote><font color="#ff0000"><b>溫馨提示</b></font>: 隱藏內容需要<a href="#respond" title="點擊進行評論"> 回復評論 </a>后才能查看, 評論后請 <strong><a href="javascript:location.reload()" title="點擊刷新"> 刷新 !</a></strong>.</blockquote></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@boke8.net"; //把左面的郵箱換成博主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'); |
注:把代碼中的“xxx@boke8.net”換成博主郵箱地址
| 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 | function reply_to_read($atts, $content=null) { ????extract(shortcode_atts(array("notice" => '<p class="reply-to-read" style="text-align:center; border:2px solid #f00; border-style:dotted; border-radius:4px; padding:5px; margin:10px;"><strong style="color: red;">溫馨提示:</strong>為了避免資源鏈接被和諧,此處內容需要您<strong><a href="#respond" title="點擊進行評論"> 回復評論 </a></strong>后才能查看, 評論后請 <strong><a href="javascript:location.reload()" title="點擊刷新"> 刷新!</a></strong></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 = "970852638@qq.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'); |
這樣就可以讓別人只有回復了評論才能下載你網站資源的效果,是不是很有逼格,我今天剛使用了這個就有了新的評論呢。
參考網址:http://www.boke8.net/the-wp-post-visible-when-comments.html
?
轉載于:https://www.cnblogs.com/shenjieblog/p/5061250.html
總結
以上是生活随笔為你收集整理的纯代码实现wordpress文章隐藏内容评论可见的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C++ 自由存储区是否等价于堆?
- 下一篇: bzoj:1666: [Usaco200