实现简介

顾名思义,关注公众号并回复关键字获取验证码后,才能查看到文章中的隐藏内容,这个功能比较适合有价值的内容文章和有推广微信公众号的站长!

代码相关

  1. /**
  2.      * WordPress文章部分内容关注微信公众号后可见 
  3.      */
  4.     function lxtx_secret_content($atts$content=null){
  5.      extract(shortcode_atts(array(‘key’=>null,’keyword’=>null), $atts));
  6.      if(isset($_POST[‘secret_key’]) && $_POST[‘secret_key’]==$key){
  7.      return ‘<div class=“secret-password”>’.$content.'</div>’;
  8.      } else {
  9.      return
  10.      ‘<div class=“post_hide_box”>
  11.      <img class=“erweima” align=“right” src=“改为二维码图片的网址” width=“150” height=“150” alt=“你的二维码名字”><div class=“post-secret”><i class=“fa fa-exclamation-circle”></i>此处内容已经被作者无情的隐藏,请输入验证码查看内容</div>
  12.      <form action=“‘.get_permalink().'” method=“post”>
  13.      <span>验证码:</span><input id=“pwbox” type=“password” size=“20” name=“secret_key”>
  14.      <a class=“a2” href=“javascript:;”><input type=“submit” value=“提交” name=“Submit”></a>
  15.      </form>
  16.      <div class=“details”>请关注“你的名字”官方QQ公众号,回复关键字“<span>’.$keyword.'</span>”,获取验证码。【注】用手机QQ扫描右侧二维码都可以关注“你的名字”官方QQ公众号。</div>
  17.      </div>’;
  18.      }
  19.     }
  20.     add_shortcode(‘gzh2v’, ‘lxtx_secret_content’);

CSS样式

  1. .post_hide_box, .secret-password {
  2.     backgroundnone repeat scroll 0 0 #efe;
  3.     border-left5px solid #e74c3c;
  4.     color#555;
  5.     padding10px 0 10px 10px;
  6.     border-radius: 5px;
  7.     margin-bottom15px;
  8.     overflowhidden;
  9.     clearboth;
  10. }
  11. .post_hide_box .post-secret {
  12.     font-size18px;
  13.     line-height20px;
  14.     color#e74c3c;
  15.     margin5px;
  16. }
  17. .post_hide_box form {
  18.     margin15px 0;
  19. }
  20. .post_hide_box form span {
  21.     font-size18px;
  22.     font-weight: 700;
  23. }
  24. .post_hide_box .erweima {
  25.     margin-left20px;
  26.     margin-right16px;
  27. }
  28. .post_hide_box input[type=password] {
  29.     color#9ba1a8;
  30.     padding6px;
  31.     background-color#f6f6f6;
  32.     border1px solid #e4e6e8;
  33.     font-size12px;
  34.     -moz-transition: border .25s linear,color .25s linear,background-color .25s linear;
  35.     -webkit-transition: border .25s linear,color .25s linear,background-color .25s linear;
  36.     -o-transition: border .25s linear,color .25s linear,background-color .25s linear;
  37.     transition: border .25s linear,color .25s linear,background-color .25s linear;
  38. }
  39. .post_hide_box input[type=submit] {
  40.     background#F88C00;
  41.     bordernone;
  42.     border2px solid;
  43.     border-color#F88C00;
  44.     border-leftnone;
  45.     border-topnone;
  46.     padding0px;
  47.     width100px;
  48.     height38px;
  49.     color#fff;
  50.     outline: 0;
  51.     border-radius: 0 0 2px 0;
  52.     font-size16px;
  53. }
  54. .post_hide_box .details span {
  55.     color#e74c3c;
  56. }

集成短码

  1. // 为了方便使用,在后台文本编辑器中集成该短代码。将以下代码放入 functions.php 中即可:
  2.  function lxtx_wpsites_add_gzh_quicktags() {
  3.      if (wp_script_is(‘quicktags’)){
  4.  ?>
  5.      <script type=“text/javascript”>
  6.      QTags.addButton( ‘gzh2v’, ‘ 公众号隐藏’, ‘\n[gzh2v keyword=“关键字” key=“验证码”]隐藏内容[/gzh2v]’, “” );
  7.      </script>
  8.  <?php
  9.      }
  10.  }
  11.  add_action( ‘admin_print_footer_scripts’, ‘lxtx_wpsites_add_gzh_quicktags’ );

使用方法

在文章中插入以下简码,修改相关内容即可:

  1. [gzh2v keyword=“关键字” key=“验证码”]隐藏内容[/gzh2v]

微信公众号

这里以微信公众号为例(QQ公众号应该也是这样),在微信公众号的“自动回复-关键字自动回复”中设置好关键字(对应上面代码中的keyword)及验证码(对应上面代码中的key)。
纯代码实现WordPress内容微信关注后可见-橘子皮