评论可见功能也是很多博客平台都在用的,BIT主题自然少不了,写废话太累人了,进入主题;下面是预览图。
评论可见代码,放到wp的函数文件
function reply_read($atts, $content=null) { if (! of_get_option('reply_read_d')) { //这部分不要学,因为这是BIT主题的判断字符,判断开启和关闭 extract(shortcode_atts(array("notice" => ' <div class="reply-read bk"> <div class="reply-ts"> <div class="read-sm"><i class="be be-info"></i>' . sprintf(__( '此处为隐藏的内容!', 'begin' )) . '</div> <div class="read-sm"><i class="be be-loader"></i>' . sprintf(__( '发表评论并刷新,方可查看', 'begin' )) . '</div> </div> <div class="read-pl"><a href="#respond" class="flatbtn"><i class="be be-speechbubble"></i>' . sprintf(__( '发表评论', 'begin' )) . '</a></div> <div class="clear"></div> </div> '), $atts)); } else { extract(shortcode_atts(array("notice" => ' <div class="hide-content bk"> <div class="hide-ts"> <div class="read-sm">' . of_get_option('reply_read_t') . '</div> <div class="read-sm">' . of_get_option('reply_read_c') . '</div> </div> <div class="hide-pl" style="background-image: url(' . of_get_option('read_img') . ');"><a href="#respond" class="flatbtn">' . sprintf(__( '评论', 'begin' )) . '</a></div> <div class="clear"></div> </div> '), $atts)); } $email = null; $user_ID = (int) wp_get_current_user()->ID; if ($user_ID > 0) { $email = get_userdata($user_ID)->user_email; if ( current_user_can('level_10') ) { return '<div class="hide-t">' . sprintf(__( '隐藏的内容', 'begin' )) . '</div><div class="secret-password">'.do_shortcode( $content ).'</div><div class="secret-b"></div>'; } } 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('<div class="hide-t">' . sprintf(__( '隐藏的内容', 'begin' )) . '</div><div class="secret-password">'.do_shortcode( $content ).'</div><div class="secret-b"></div>'); } else { return $notice; } } add_shortcode('reply', 'reply_read');
前端的评论可见的短代码
函数文件放好后,前端的评论可见的短代码则是[ reply ][ /reply ]
提示:不一定要按照这个来,上面其实可以删减很多的,我这边这是写了判断
需要使用js引入后台安装在编辑器上面
function begin_add_tinymce_plugin( $plugin_array ) { $plugin_array['bit_mce_button'] = get_bloginfo( 'template_url' ) . '/js/js文件名称'; return $plugin_array; } function begin_register_mce_button( $buttons ) { array_push( $buttons, 'bit_mce_button' ); return $buttons; }
嵌入wp编辑器的js
(function() { tinymce.PluginManager.add('begin_mce_button', function( editor, url ) { editor.addButton( 'begin_mce_button', { text: false, icon: 'editimage', title : '短代码', type: 'menubutton', menu: [ { text: '内容保护', menu: [ { { text: '回复可见', icon: 'bubble', onclick: function() { selected = tinyMCE.activeEditor.selection.getContent(); editor.insertContent('[ reply ]'+selected+'[ /reply ]'); } }, }); }); })();