WordPress文章部分隐藏内容 输入密码可见


偶然看到一个动态图的WP站,所有的车牌必须输入密码才可见。觉得蛮好玩的,就搜寻网络找到此功能的代码,这里就是直接分享给各位站长朋友!相信一些类型站的配合这个功能绝对是一款神器!比如你可以把你要一些关键内容隐藏掉,如下载地址之类的!然后设置好查看密码。然后把查看密码丢到公众号上,轻轻松松做到吸粉!但是这个功能还是有消耗服务器资源的!大家自己斟酌使用!

网上找到的样式代码有一个CSS溢出的问题,现在已经给大家修复了!下面先看功能效果图吧!

实现方法:

将下面的代码放入主题的函数模板(functions.php)

/* Name: 部分内容输入密码可见(短代码) * 屌丝青年网(www.dsqnw.com) */ function e_secret($atts, $content=null){ extract(shortcode_atts(array('key'=>null), $atts)); if(isset($_POST['e_secret_key']) && $_POST['e_secret_key']==$key){ return ' <div class="e-secret">'.$content.'</div> '; } else{ return ' <form class="e-secret" action="'.get_permalink().'" method="post" name="e-secret"><label>输入密码查看加密内容:</label><input type="password" name="e_secret_key" class="euc-y-i" maxlength="50"><input type="submit" class="euc-y-s" value="确定"> <div class="euc-clear"></div> </form> '; } } add_shortcode('secret','e_secret');

将下面的样式代码放入自己的主题CSS中(style.css)

/*e-secret*/ .e-secret { margin: 20px 0; padding: 20px; background: #f8f8f8; overflow: auto; } .e-secret input.euc-y-i[type="password"] { float: left; background: #fff; width: 100%; line-height: 36px; margin-top: 5px; border-radius: 3px; } .e-secret input.euc-y-s[type="submit"] { float: right; margin-top: -47px; width: 30%; margin-right: 1px; border-radius: 0 3px 3px 0; } input.euc-y-s[type="submit"]{background-color:#FF0016;color:#fff;font-size:21px;box-shadow:none;-webkit-transition: .4s;-moz-transition: .4s;-o-transition: .4s;transition:.4s;-webkit-backface-visibility:hidden;position:relative;cursor:pointer;padding: 13px 20px;text-align: center;border-radius: 50px;-webkit-box-shadow: none; -moz-box-shadow: none; box-shadow: none;border: 0;height: auto;outline: medium;line-height: 20px;margin: 0;} input.euc-y-s[type="submit"]:hover{background-color:#CE0416;} input.euc-y-i[type="text"],input.euc-y-i[type="password"]{border:1px solid #F2EFEF;color:#777;display:block;background: #FCFCFC;font-size:18px;transition:all .5s ease 0;outline:0;box-sizing:border-box;-webkit-border-radius:25px;-moz-border-radius:25px;border-radius:25px;padding:5px 16px; margin: 0;height: auto;line-height: 30px;} input.euc-y-i[type="text"]:hover,input.euc-y-i[type="password"]:hover{border:1px solid #56b4ef;box-shadow:0 0 4px #56b4ef

在文章中使用短代码secret调用,示例:

[secret key="设置密码"] 加密内容 [/secret]

完成以上内容,那就抓紧发布的测试文章试试吧!不要忘记点赞哦!

补充个代码,我估计很多站长每次用这个功能的时候,都要专门去找下上面的调用短代码是什么,所以较大家一个一劳永逸的方法

将下面的代码放入主题的函数模板(functions.php)

// 面板插入按钮 function appthemes_add_quicktags() { ?> <script type="text/javascript"> QTags.addButton( 'd2', '高亮', '<pre class="prettyprint">高亮代码</pre删除这里>' ); </script> <?php } add_action('admin_print_footer_scripts', 'appthemes_add_quicktags' );

把上面加入functions.php后,你就可以在文本编辑器看到这个插入按钮了

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM