Previously, I helped others test the comments visibility function and tried it in the previous article "add wordcount statistics for WordPress". It still seems to be a good practical function, which can increase the comments enthusiasm of visitors, A lot of useless spam messages may also be added. Common functions on forums may be annoying when many messages are used. However, many children's shoes are very interested in this, so I will post the implementation method.
First, we recommend a plug-in to implement this function: easy2hide.
Usage: After the plug-in is enabled, add the following content when editing the article:
- <! -- Easy2hide start {reply_to_this = true} --> some hidden content <! -- Easy2hide end -->
Let's talk about the implementation method without plug-ins. The original code of this method should be from: Messy.
The original code has a disadvantage that even the blogger or Webmaster can see the hidden content only after commenting, so someone has improved the code. The specific source of the Code is unknown. Please let us know if someone claims it.
Add the following code to the topic functions. php file:
- Function reply_to_read ($ atts, $ content = null ){
- Extract (export code_atts (array ("notice" => '<p class = "reply-to-read"> tips: the content here can be viewed only after <a href = "# respond" title = "comment on this article"> comment on this article </a>. </p> '), $ atts ));
- $ Email = null;
- $ User_ID = (int) wp_get_current_user ()-> ID;
- If ($ user_ID> 0 ){
- $ Email = get_userdata ($ user_ID)-> user_email;
- // Directly display the content of the blogger
- $ Admin_email = "xxx@aaa.com"; // blogger 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 _ apache' = '1' and 'comment _ author_email '=' {$ email} 'LIMIT 1 ";
- If ($ wpdb-> get_results ($ query )){
- Return do_response code ($ content );
- } Else {
- Return $ notice;
- }
- }
-
- Add_response code ('reply', 'reply _ to_read ');
Modify the Email address of the blogger.
Usage: add the following when editing an article:
- [@ Reply] comments visible content [@/reply]
Or
- [@ Reply notice = "Custom prompt information"] comments visible content [@/reply]
Tip: remove @
Demo: add article count statistics for WordPress