欢迎您光临本站,秉承服务宗旨,履行"站长"责任,销售只是起点,服务永无止境!

【WordPress教程】纯代码实现设置密码访问

作者 : 觅站网 本文共2687个字,预计阅读时间需要7分钟 发布时间: 2021-01-28 共186人阅读
  • 1030
  • 拼搏
  • 也想出现在这里? 联系我们

    1.首先载入美化的css

    以本站为例,可以直接在后台>自定义代码添加css,其他模板可以自行添加模板文件里的style.css或是其他文件里,代码如下
    提示框代码

     /**tishikuang**/
    #sc_notice{color:#7da33c;background:#ecf2d6 url(../img/sc_notice.png) -1px -1px no-repeat;border:1px solid #aac66d;overflow:hidden;margin:10px 0;padding:15px 15px 15px 35px}
    #sc_warn{color:#ad9948;background:#fff4b9 url(../img/sc_warn.png) -1px -1px no-repeat;border:1px solid #eac946;overflow:hidden;margin:10px 0;padding:15px 15px 15px 35px}
    #sc_error{color:#c66;background:#ffecea url(../img/sc_error.png) -1px -1px no-repeat;border:1px solid #ebb1b1;overflow:hidden;margin:10px 0;padding:15px 15px 15px 35px}
    #sc_tips{color:#777;background:#eaeaea url(../img/sc_tips.png) -1px -1px no-repeat;border:1px solid #ccc;overflow:hidden;margin:10px 0;padding:15px 15px 15px 35px}
    #sc_blue{color:#4d99d2;background:#dbe7f8 url(../img/sc_blue.png) -1px -1px no-repeat;border:1px solid #4d99d2;overflow:hidden;margin:10px 0;padding:15px 15px 15px 35px}.sc_act{margin:10px 0;padding:10px 15px;background:#FFF;border:1px solid #e3e3e3;border-left:3px solid #3dabce}.sc_act:hover{background:#fcfcfc}
    .tm-btn,
    .button,
    input[type="submit"]{color: #fff; background: #fd6639;color : #fff; background-image: none; background-color: #fd6639; color : #fff;padding: 0 25px; font-weight: bold; cursor: pointer; border: none; height: 36px; line-height: 36px; -webkit-border-radius: 2px; -moz-border-radius: 2px; -ms-border-radius: 2px; -o-border-radius: 2px; border-radius: 2px; -webkit-transition: all 0.2s ease-in-out 0s; -moz-transition: all 0.2s ease-in-out 0s; -o-transition: all 0.2s ease-in-out 0s; -ms-transition: all 0.2s ease-in-out 0s; transition: all 0.2s ease-in-out 0s; display: inline-block; margin: 5px;}
    .tm-btn.small,
    .button.small,
    input[type="submit"].small{padding: 5px 10px; height: auto; line-height: 1.8;color: #fff;}
    
    .tm-btn.green,
    .button.green,
    input[type="submit"].green{background: #7cc576;color : #fff;}
    

    以上提供的是本站的一套美化方案,如果你有更好的,可以自己修改,上面的css也不仅仅有单单一个功能,可用于其他

    2.打开主题目录的functions.php文件添加以下代码

    //部分内容输入密码可见
    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" id="sc_notice"><strong><span style="color: #ff6600;">隐藏内容:</span></strong><br> '.$content.'</div>';
    }
    else{
    return '<div id="sc_warn"><form class="e-secret" action="'.get_permalink().'" method="post" name="e-secret">
    <strong><span style="color: #ff6600;">此部分内容加密,请输入密码查看</span></strong><br><label>密码:</label><input type="password" name="e_secret_key" class="euc-y-i" maxlength="60">
    <input type="submit" class="tm-bin green small" value="提取"><div class="euc-clear"></div> </form></div>';
    }
    }
    add_shortcode('secret','e_secret');
    

    3.文章编辑时引用

    【secret key="密码"】隐藏内容【/secret】
    

     

    1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
    2. 分享目的仅供大家学习和交流,请不要用于商业用途!
    3. 如果你也有好源码或者教程,可以到用户中心发布,分享有积分奖励和额外收入!
    4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
    5. 如有链接无法下载、失效或广告,请联系管理员处理!
    6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
    7. 如遇到加密压缩包,默认解压密码为"mobanxi.com",如遇到无法解压的请联系管理员!
    8. 因为资源和程序源码均为可复制品,所以不支持任何理由的退款兑现,请斟酌后支付下载
    声明如果标题没有注明"已测试"或者"测试可用"等字样的资源源码均未经过站长测试.特别注意没有标注的源码不保证任何可用性

    模板系 » 【WordPress教程】纯代码实现设置密码访问
    也想出现在这里? 联系我们

    常见问题FAQ

    免费下载或者VIP会员专享资源能否直接商用?
    本站所有资源版权均属于原作者所有,这里所提供资源均只能用于参考学习用,请勿直接商用。若由于商用引起版权纠纷,一切责任均由使用者承担。更多说明请参考 VIP介绍。

    发表回复

    加入VIP免费获取全站资源

    立即查看 了解详情
    Copyright © 2018-2021MOBANXI.COM All Rights Reserved -桂ICP备17012970号
    开通VIP 享更多特权,建议使用QQ登录