偶然看到一個動態圖的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