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