Some content of WordPress articles can be seen after following WeChat official account

 Watson Blog September 15, 2017 19:16:41 WordPress comment two hundred and thirty-two Reading mode

Only after following the public account and replying to the keyword to obtain the verification code can you view the hidden content in the article. But I haven't figured out how to use it. Let's pick it up and use it today~

1 Core code

Put the following code into functions.php (PS: I hid the code to make a DEMO~):

  1. /**
  2. ?*? Some content of WordPress articles can be seen after following WeChat official account? -? The dragon laughs at the world
  3. ?*? http://www.ilxtx.com/view-contents-by-following-wechat-official-accounts.html
  4. ?*/
  5. function ? lxtx_secret_content( $atts ,? $content =null){
  6. ???? extract(shortcode_atts( array ('key'=>null,'keyword'=>null),? $atts ));
  7. ???? if (isset( $_POST ['secret_key'])?&&? $_POST ['secret_key']== $key ){
  8. ???????? return ?'< div? class = "secret-password" >'. $content .'</div>';
  9. ????}? else ? {
  10. ???????? return
  11. ????????????'< div? class = "post_hide_box" >
  12. ?????????????< img? class = "erweima" ? align= "right" ? src= "Change to the URL of the QR code picture" ? width= "150" ? height= "150" ? alt= "Your QR code name" ><div? class = "post-secret" ><i? class = "fa?fa-exclamation-circle" ></i>The content here has been mercilessly hidden by the author. Please enter the verification code to view the content</div>
  13. ?????????????< form?action= "'.get_permalink().'" ? method= "post" >
  14. ?????????????< Span>Verification code:</span><input? id= "pwbox" ? type= "password" ? size= "20" ? name= "secret_key" >
  15. ?????????????< a? class = "a2" ? href= "javascript:;" ><input? type= "submit" ? value= Submit ? name= "Submit" ></a>
  16. ?????????????</ form>
  17. ?????????????< div? class = "details" >Please follow the official QQ official account of "your name" and reply to the keyword "<span>' $keyword . '</span>"to obtain the verification code. [Note] You can follow the official QQ official account of "your name" by scanning the QR code on the right with mobile QQ</ div>
  18. ?????????????</ div>';
  19. ????}
  20. }
  21. add_shortcode('gzh2v',?' lxtx_secret_content');

Pay attention to the relevant content in the code!

2 Front CSS style

Put the following code in your theme's style.css file:

  1. .post_hide_box,?. secret-password{ backgroundWordPress文章部分内容关注微信公众号后可见 none ? repeat ? scroll ? 0? 0? #efe ; border-leftWordPress文章部分内容关注微信公众号后可见 5px ? solid ? #e74c3c ; colorWordPress文章部分内容关注微信公众号后可见 #555 ; paddingWordPress文章部分内容关注微信公众号后可见 10px ? 0? 10px ? 10px ; border -radius:? 5px ; margin-bottomWordPress文章部分内容关注微信公众号后可见 15px ; overflow : hidden ;? clear : both ;}
  2. .post_hide_box?. post-secret{ font-sizeWordPress文章部分内容关注微信公众号后可见 18px ;? line-height : 20px ;? color : #e74c3c ;? margin : 5px ;}
  3. .post_hide_box? form{? margin : 15px ? 0;}
  4. .post_hide_box? form?span{? font-size : 18px ;? font-weight :700;}
  5. .post_hide_box?. erweima{? margin-left : 20px ;? margin-right : 16px ;}
  6. .post_hide_box? input[type=password]{? colorWordPress文章部分内容关注微信公众号后可见 #9ba1a8 ;? paddingWordPress文章部分内容关注微信公众号后可见 6px ;? background-colorWordPress文章部分内容关注微信公众号后可见 #f6f6f6 ;? borderWordPress文章部分内容关注微信公众号后可见 1px ? solid ? #e4e6e8 ;? font-sizeWordPress文章部分内容关注微信公众号后可见 12px ;- moz-transition:? border ?. 25s? linear, color ?. 25s? linear, background-color ?. 25s? linear;?-webkit-transition:? border ?. 25s? linear, color ?. 25s? linear, background-color ?. 25s? linear;?-o-transition:? border ?. 25s? linear, color ?. 25s? linear, background-color ?. 25s? linear;?transition:? border ?. 25s? linear, color ?. 25s? linear, background-color ?. 25s? linear;}
  7. .post_hide_box? input[type=submit]? {? backgroundWordPress文章部分内容关注微信公众号后可见 #F88C00 ;? borderWordPress文章部分内容关注微信公众号后可见 none ;? borderWordPress文章部分内容关注微信公众号后可见 2px ? solid ; border-colorWordPress文章部分内容关注微信公众号后可见 #F88C00 ;? border-leftWordPress文章部分内容关注微信公众号后可见 none ;? border-topWordPress文章部分内容关注微信公众号后可见 none ;? paddingWordPress文章部分内容关注微信公众号后可见 0px ; widthWordPress文章部分内容关注微信公众号后可见 100px ;? heightWordPress文章部分内容关注微信公众号后可见 38px ;? colorWordPress文章部分内容关注微信公众号后可见 #fff ;? outline :? 0; border -radius:? 0? 0? 2px ? 0;? font-sizeWordPress文章部分内容关注微信公众号后可见 16px ;}
  8. .post_hide_box?. details?span{ color : #e74c3c ;}

3 Integrated short code

To facilitate use, the short code is integrated in the background text editor. Put the following code into functions.php:

  1. //? Add public account hidden simplified code button in background text editing box
  2. function ? lxtx_wpsites_add_gzh_quicktags()? {
  3. ???? if ? (wp_script_is('quicktags')){
  4. ?>
  5. ????< script?type= "text/javascript" >
  6. ???? QTags.addButton(?' gzh2v',?'? Public ID hidden ',?' \n[gzh2v?keyword= Keywords ? key= Verification code ]Hidden content [/gzh2v] ',? "" ?);
  7. ????</ script>
  8. <? php
  9. ????}
  10. }
  11. add_action(?' admin_print_footer_scripts',?'lxtx_wpsites_add_gzh_quicktags'?);

4 Usage

4.1 Using short codes in articles

Of course, it is OK not to write the simple code button. When writing an article, use the following output code:

Insert the following simplified code and modify relevant contents:

  1. [gzh2v?keyword= Keywords ? key= Verification code ]Hide content [/gzh2v]

4.2 WeChat official account

Here we take the WeChat public account as an example (the same should be true for the QQ public account). Set the keywords (corresponding to the keyword in the code above) and verification code (corresponding to the key in the code above) in the "Automatic reply - keyword automatic reply" of the WeChat public account.

5 Extension

In fact, this article is consistent with the common code principle of "part of the content of the article can be seen after reply" or "part of the content of the article can be seen after login", but it is just combined with the public account. You can integrate it into your own theme!

This procedure is not tested and is stored for use.

 Watson Blog
  • This article is written by Published on September 15, 2017 19:16:41
  • This article is collected and sorted by the website of Mutual Benefit, and the email address for problem feedback is: wosnnet@foxmail.com , please keep the link of this article for reprinting: https://wosn.net/559.html

Comment