知識(shí)
不管是網(wǎng)站,軟件還是小程序,都要直接或間接能為您產(chǎn)生價(jià)值,我們?cè)谧非笃湟曈X表現(xiàn)的同時(shí),更側(cè)重于功能的便捷,營(yíng)銷的便利,運(yùn)營(yíng)的高效,讓網(wǎng)站成為營(yíng)銷工具,讓軟件能切實(shí)提升企業(yè)內(nèi)部管理水平和效率。優(yōu)秀的程序?yàn)楹笃谏?jí)提供便捷的支持!
您當(dāng)前位置>首頁(yè) » 新聞資訊 » 公眾號(hào)相關(guān) >
WordPress主題純代碼實(shí)現(xiàn)文章設(shè)置隱藏內(nèi)容公眾號(hào)可見教程
發(fā)表時(shí)間:2020-10-10
發(fā)布人:葵宇科技
瀏覽次數(shù):69
1 核心代碼
部分轉(zhuǎn)自鉆芒博客,其它代碼又冪彀社區(qū)和菜鳥站長(zhǎng)之家代改進(jìn)而來(lái),不會(huì)影響圖片燈箱。將以下代碼放入 functions.php 中:
/**
* WordPress文章部分內(nèi)容關(guān)注微信公眾號(hào)后可見
*/
function weixingzh_secret_content($atts, $content=null){
extract(shortcode_atts(array('key'=>null,'keyword'=>null), $atts));
if(isset($_POST['secret_key']) && $_POST['secret_key']==$key){
return '<div class="secret-password">'.$content.'</div>';
} else {
return '<link rel="stylesheet" href="https://cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.css">
<div class="gzhhide">
<div class="gzhtitle">抱歉!隱藏內(nèi)容,請(qǐng)輸入密碼后可見!<i class="fa fa-lock"></i><span></span></div>
<div class="gzh-content">請(qǐng)打開微信掃描右邊的二維碼回復(fù)關(guān)鍵字“<span><b>'.$keyword.'</b></span>”獲取密碼,也可以微信直接搜索“科技小新”關(guān)注微信公眾號(hào)獲取密碼。
<div class="gzhcode" style="background: url(https://www.cnzzzj.com/wp-content/uploads/2020/09/wxgzh.jpg);background-size: 100%;" width="140" height="140" alt="菜鳥福利之家"></div>
</div>
<div class="gzhbox"><form action="'.get_permalink().'" method="post">
<input id="pwbox" type="password" size="20" name="secret_key">
<button type="submit">立即提取</button></form></div></div>';
}
}
add_shortcode('weixingzh', 'weixingzh_secret_content');
// 后臺(tái)文本編輯框中添加公眾號(hào)隱藏簡(jiǎn)碼按鈕
function wpsites_add_weixingzh_quicktags() {
if (wp_script_is('quicktags')){
?>
<script type="text/javascript">
QTags.addButton( 'weixingzh', '公眾號(hào)隱藏', '[weixingzh keyword="關(guān)鍵字" key="驗(yàn)證碼"]隱藏內(nèi)容[/weixingzh]',"" );
</script>
<?php
}
}
add_action( 'admin_print_footer_scripts', 'wpsites_add_weixingzh_quicktags' );
2 前端 CSS 樣式一
之前有很多小伙伴反應(yīng)css鏈入錯(cuò)誤。大家別用鏈入方法了,直接把下邊的css丟到主題的style.css即可。本次還修復(fù)了 小鎖圖標(biāo)傾斜的問題,然后把上面的https://cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.css外鏈CSS去掉。
/** 純代碼實(shí)現(xiàn)WordPress文章設(shè)置隱藏內(nèi)容公眾號(hào)可見*/
.post_hide_box, .secret-password{background: none repeat scroll 0 0 #efe;border-left: 5px solid #e74c3c;color: #555;padding: 10px 0 10px 10px;border-radius: 5px;margin-bottom: 15px;overflow:hidden; clear:both;}
.post_hide_box .post-secret{font-size: 18px; line-height:20px; color:#e74c3c; margin:5px;}
.post_hide_box form{ margin:15px 0;}
.post_hide_box form span{ font-size:18px; font-weight:700;}
.post_hide_box .erweima{ margin-left:20px; margin-right:16px;}
.post_hide_box input[type=password]{ color: #9ba1a8; padding: 6px; background-color: #f6f6f6; border: 1px solid #e4e6e8; font-size: 12px;-moz-transition: border .25s linear,color .25s linear,background-color .25s linear; -webkit-transition: border .25s linear,color .25s linear,background-color .25s linear; -o-transition: border .25s linear,color .25s linear,background-color .25s linear; transition: border .25s linear,color .25s linear,background-color .25s linear;}
.post_hide_box input[type=submit] { background: #F88C00; border: none; border: 2px solid;border-color: #F88C00; border-left: none; border-top: none; padding: 0px;width: 100px; height: 38px; color: #fff; outline: 0;border-radius: 0 0 2px 0; font-size: 16px;}
.post_hide_box .details span{color:#e74c3c;}
.post_hide_box .details
span{color:#e74c3c;}
.gzhhide{background:#fff;border-radius:10px;padding:20px;margin:15px 0;position:relative;box-shadow:0 0 20px #d0d0d0}
.gzhhide .gzhtitle{position:relative;font-size:17px;font-weight:700;color:#6c80a7;padding:6px 140px 0 40px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.gzhhide .gzhtitle .fa{position:absolute;left:0;font-size:35px;top:0}
.gzh-content{padding:20px 140px 15px 0;font-size:14px;color:#777}
.gzhbox{padding:0 140px 10px 0}
.gzhbox input{
width:45%;
border:none;
color:#737373;
font-size:13px;
height:35px;line-height:35px;background:#f2f2f2;border-radius:4px;
outline:none;float:left;padding:0 10px}
.gzhbox button{width:20%;margin-left:15%;
border:none;background:#3b8cff;color:#fff;padding:5px 0;font-size:14px;border-radius:5px}
.gzhhide .gzhcode{position:absolute;width:140px;height:140px;right:20px;top:50%;margin-top:-50px}
#vivideo{height:200px}
.gzhhide .gzhtitle i {font-style:normal;}
前端CSS樣式二
/*純代碼實(shí)現(xiàn)WordPress文章設(shè)置隱藏內(nèi)容公眾號(hào)可見*/
.post_hide_box, .secret-password{background: none repeat scroll 0 0 #efe;color: #555;padding: 10px 0 10px 10px;border-radius: 5px;margin-bottom: 15px;overflow:hidden; clear:both;}
.post_hide_box .post-secret{font-size: 18px; line-height:20px; color:#e74c3c; margin:5px;}
.post_hide_box form{ margin:15px 0;}
.post_hide_box form span{ font-size:18px; font-weight:700;}
.post_hide_box .erweima{ margin-left:20px; margin-right:16px;}
.post_hide_box input[type=password]{ color: #9ba1a8; padding: 6px; background-color: #f6f6f6; border: 1px solid #e4e6e8; font-size: 12px;-moz-transition: border .25s linear,color .25s linear,background-color .25s linear; -webkit-transition: border .25s linear,color .25s linear,background-color .25s linear; -o-transition: border .25s linear,color .25s linear,background-color .25s linear; transition: border .25s linear,color .25s linear,background-color .25s linear;}
.post_hide_box input[type=submit] {
background: #F88C00;
border: none;
border: 2px solid;
border-color: #F88C00;
border-left: none;
border-top: none;
padding: 0px;
width: 100px;
height: 28px;
color: #fff;
outline: 0;
border-radius: 0 0 2px 0;
font-size: 16px;
}
.post_hide_box .details span{color:#e74c3c;}
.post_hide_box .post_secret_left {
width: 75%;
float: left;
}
.post_hide_box .post_secret_right{
width: 25%;
float: right;
}
.post_hide_box .post_secret_right_img {
background-size: 100%;
background-repeat: no-repeat;
width: 150px;
height: 150px;
margin: 0 auto;
}
@media screen and (max-width:480px){
.post_hide_box .post_secret_left {
width: 100%;
float: none;
}
.post_hide_box .post_secret_right{
width: 100%;
float: none;
}
}
3 集成短代碼
菜鳥站長(zhǎng)之家為了方便使用,在后臺(tái)文本編輯器中集成該短代碼。將以下代碼放入 functions.php 中即可:
/*WordPress-文章部分內(nèi)容關(guān)注微信公眾號(hào)后可見**/
function gzh2v_secret_content($atts, $content=null){
extract(shortcode_atts(array('key'=>null,'keyword'=>null), $atts));
if(isset($_POST['secret_key']) && $_POST['secret_key']==$key){
return '<div class="secret-password">'.$content.'</div>';
} else {
return '<link rel="stylesheet" href="https://cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.css">
<div class="post_hide_box">
<div class="post_secret_left">
<div class="post-secret"><i class="fa fa-lock"></i> 此處內(nèi)容已經(jīng)被作者隱藏,請(qǐng)輸入驗(yàn)證碼查看內(nèi)容</div>
<form action="'.get_permalink().'" method="post">
<span>驗(yàn)證碼:</span><input id="pwbox" type="password" size="20" name="secret_key">
<a class="a2" href="javascript:;"><input type="submit" value="提交" name="Submit"></a>
</form>
<div class="details"> 請(qǐng)關(guān)注“菜鳥福利之家”官方微信公眾號(hào),回復(fù)關(guān)鍵字“<span><b>'.$keyword.'</b></span>”,獲取驗(yàn)證碼!<br>【注】用手機(jī)微信掃描右側(cè)二維碼即可關(guān)注“菜鳥福利之家”微信公眾號(hào)。</div>
</div>
<div class="post_secret_right">
<div class="post_secret_right_img" style="background-image: url(https://www.cnzzzj.com/wp-content/uploads/2020/09/wxgzh.jpg);"></div>
</div>
</div>';
}
}
add_shortcode('gzh2v', 'gzh2v_secret_content');
// 后臺(tái)文本編輯框中添加公眾號(hào)隱藏簡(jiǎn)碼按鈕
function wpsites_add_gzh2v_quicktags() {
if (wp_script_is('quicktags')){
?>
<script type="text/javascript">
QTags.addButton( 'gzh2v', '公眾號(hào)隱藏', '<div class="secret-password">隱藏內(nèi)容</div>',"" );
</script>
<?php
}
}
add_action( 'admin_print_footer_scripts', 'wpsites_add_gzh2v_quicktags' );
4 使用方法
4.1 在文章中使用短代碼
4.2 微信公眾號(hào)
這里以微信公眾號(hào)為例(QQ 公眾號(hào)同理),在微信公眾號(hào)的“自動(dòng)回復(fù)-關(guān)鍵字自動(dòng)回復(fù)”中設(shè)置好關(guān)鍵字(對(duì)應(yīng)上面代碼中的 keyword)及驗(yàn)證碼(對(duì)應(yīng)上面代碼中的 key)。
還有一個(gè)方法是集成在編輯器按鈕上:
在functions.php引入代碼:
/*WordPress-文章部分內(nèi)容關(guān)注微信公眾號(hào)后可見引入*/
require_once get_template_directory() . '/customfun/custom-fun.php';
下載文件放到根目錄,如果你改過functions.php,就加入上面的代碼,沒改過就覆蓋。
演示截圖:
2020.10.8更新管理員可見代碼:
global $user_ID;
if( $user_ID && current_user_can('level_10') ) :
return '<div class="secret-password">'.$content.'</div>';
endif;
把上面的代碼加入到下面
extract(shortcode_atts(array('key'=>null,'keyword'=>null), $atts));
下載地址:https://cnitzy.lanzoui.com/i3Qd6gx85he
相關(guān)案例查看更多
相關(guān)閱讀
- 網(wǎng)站開發(fā)
- 小程序密鑰
- 云南小程序開發(fā)報(bào)價(jià)
- 政府網(wǎng)站建設(shè)服務(wù)
- 汽車報(bào)廢系統(tǒng)
- 云南省建設(shè)廳網(wǎng)站官網(wǎng)
- 軟件開發(fā)
- 云南網(wǎng)站建設(shè)公司地址
- 網(wǎng)站制作哪家好
- 云南小程序代建
- 大理網(wǎng)站建設(shè)公司
- 網(wǎng)站建設(shè)快速優(yōu)化
- 表單
- 小程序被騙
- 模版信息
- 報(bào)廢車管理
- 微信分銷
- 百度小程序開發(fā)
- 企業(yè)網(wǎng)站
- 云南網(wǎng)絡(luò)推廣
- 網(wǎng)站建設(shè)靠譜公司
- 網(wǎng)站搭建
- 大理小程序開發(fā)
- 云南做百度小程序的公司
- 云南網(wǎng)站建設(shè)制作
- 云南小程序開發(fā)制作
- 安家微信小程序
- 報(bào)廢車回收管理軟件
- web
- 報(bào)廢車拆解回收管理系統(tǒng)