WordPress教程:WordPress添加回复可见内容

自从用了7b2主题后,没有了回复可见功能,苦苦寻求找了很多都不行,经过坚持不懈的努力终于找到,下面分享下添加过程

WordPress教程:WordPress添加回复可见内容

functions.php

在主题根目录下的functions.php文件中添加以下代码:

  1. //部分内容评论可见  
  2. function reply_to_read($atts$content = null) {  
  3.  extract(shortcode_atts(array(  
  4.  "notice" => '<div class="reply">隐藏内容,回复可见“<a href="' . get_permalink() . '#respond" title="回复可见">回复本文</a>”后“<a href="javascript:window.location.reload();" title="刷新页面">刷新页面</a>”查看隐藏内容!</div>'  
  5.  ) , $atts));  
  6.  $email = null;  
  7.  $user_ID = (int)wp_get_current_user()->ID;  
  8.  if ($user_ID > 0) {  
  9.  $email = get_userdata($user_ID)->user_email;  
  10.  //对博主直接显示内容  
  11.  $admin_email = get_bloginfo('admin_email');  
  12.  if ($email == $admin_email) {  
  13.  return $content;  
  14.  }  
  15.  } else if (isset($_COOKIE['comment_author_email_' . COOKIEHASH])) {  
  16.  $email = str_replace('%40', '@', $_COOKIE['comment_author_email_' . COOKIEHASH]);  
  17.  } else {  
  18.  return $notice;  
  19.  }  
  20.  if (emptyempty($email)) {  
  21.  return $notice;  
  22.  }  
  23.  global $wpdb;  
  24.  $post_id = get_the_ID();  
  25.  $query = "SELECT `comment_ID` FROM {$wpdb->comments} WHERE `comment_post_ID`={$post_id} and `comment_approved`='1' and `comment_author_email`='{$email}' LIMIT 1";  
  26.  if ($wpdb->get_results($query)) {  
  27.  return do_shortcode($content);  
  28.  } else {  
  29.  return $notice;  
  30.  }  
  31. }  
  32. add_shortcode('reply', 'reply_to_read');  

接着需要在编辑器中添加自定义按钮functions.php添加以下代码:

  1.  //添加HTML编辑器自定义快捷标签按钮  
  2. add_action('after_wp_tiny_mce', 'bolo_after_wp_tiny_mce');  
  3. function bolo_after_wp_tiny_mce($mce_settings) {  
  4. ?>  
  5. <script type="text/javascript">  
  6. QTags.addButton( 'reply', '回复可见', '[@reply]\n\n[/reply]\n', "" );  
  7. </script>  
  8. <?php  
  9. }  

以上代码其中[@reply]中的@去掉

style.css

在主题根目录下的style.css文件中添加以下代码:

  1. /*回复可见*/
  2. .reply {
  3.   padding10px;
  4.   border1px #49aff9 dashed;
  5.   background-color#fafafa;
  6.   color#f40000;
  7.   text-aligncenter;
  8.   font-size14px;
  9. }

以上代码根据自己喜欢可以适当修改

调用代码

在文本编辑框可看到回复可见按钮,插入即可,或者输入[@reply][/reply],其中@删除掉

效果演示

[reply]
恭喜你看到了这几个字!!!
[/reply]

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
搜索