WordPress教程:WordPress添加回复可见内容
functions.php
在主题根目录下的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’);
接着需要在编辑器中添加自定义按钮functions.php添加以下代码:
- //添加HTML编辑器自定义快捷标签按钮
- add_action(‘after_wp_tiny_mce’, ‘bolo_after_wp_tiny_mce’);
- function bolo_after_wp_tiny_mce($mce_settings) {
- ?>
- <script type=“text/javascript”>
- QTags.addButton( ‘reply’, ‘回复可见’, ‘[@reply]\n\n[/reply]\n’, “” );
- </script>
- <?php
- }
以上代码其中[@reply]中的@去掉
style.css
在主题根目录下的style.css文件中添加以下代码:
- /*回复可见*/
- .reply {
- padding: 10px;
- border: 1px #49aff9 dashed;
- background-color: #fafafa;
- color: #f40000;
- text-align: center;
- font-size: 14px;
- }
以上代码根据自己喜欢可以适当修改
调用代码
在文本编辑框可看到回复可见按钮,插入即可,或者输入[@reply]和[/reply],其中@删除掉
效果演示
1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
7. 如遇到加密压缩包,默认解压密码为"lanrensheji.com",如遇到无法解压的请联系管理员!
懒人设计 » WordPress教程:WordPress添加回复可见内容
懒人设计 » WordPress教程:WordPress添加回复可见内容