欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

WORDPRESS文章中微信打賞功能的2種實(shí)現(xiàn)方法

  發(fā)布時(shí)間:2016-09-23 10:03:32   作者:佚名   我要評(píng)論
這篇文章主要介紹了WORDPRESS文章中微信打賞功能的2種實(shí)現(xiàn)方法,結(jié)合實(shí)例形式分析了2種簡(jiǎn)單的微信打賞實(shí)現(xiàn)技巧,涉及針對(duì)手機(jī)端的判斷與微信支付二維碼的調(diào)用技巧,需要的朋友可以參考下

本文實(shí)例講述了WORDPRESS文章中微信打賞功能的2種實(shí)現(xiàn)方法。分享給大家供大家參考,具體如下:

打賞功能功能就是給我們一些資助了,寫博客不容易所以會(huì)給一些內(nèi)容與說明了,下面我們就一起來看2種給WORDPRESS文章添加微信打賞功能實(shí)現(xiàn)方法.

方法一、比較專業(yè)也是比較復(fù)雜了

給WordPress文章添加微信打賞功能,如果你的博文給別人有幫助,也許會(huì)有熱心的讀者給你打賞,首先在WordPress主題的functions.php末尾添加如下代碼.

復(fù)制代碼
代碼如下:
//如果是文章頁并且不是手機(jī)訪問,在文章末尾添加一段html代碼
function add_pay($content) {
$pay = <<<PAY
<div class="gave" >
<a href="javascript:;" id="gave">打賞</a>
<div class="code" id="wechatCode" style="display: none">
<img src="/wp-content/uploads/2015/10/pay.jpg" alt="">
<div><img src="m/wp-content/uploads/2015/10/ico-wechat.jpg" alt="微信logo" class="ico-wechat">微信掃一掃,打賞作者吧~</i></div>
</div>
</div>
PAY;
if(is_single() && !wp_is_mobile()){
$content .= $pay;
}
return $content;
}
add_filter( 'the_content', 'add_pay',10);

這個(gè)函數(shù)的作用是:如果是文章頁并且不是手機(jī)訪問,在文章末尾添加一段html代碼.

在主題的css文件添加以下樣式:

復(fù)制代碼
代碼如下:
<style type="text/css">
.gave {
height: 110px;
position: relative;
text-align: center;
}
.gave .code::after {
border-color: #fff transparent transparent;
border-style: solid;
border-width: 10px;
content: "";
height: 0;
left: 50%;
margin-left: -7.5px;
position: absolute;
top: 100%;
width: 0;
}
.gave .code {
background: #fff none repeat scroll 0 0;
border-radius: 5px;
bottom: 100%;
box-shadow: 0 0 15px #e5e5e5;
color: #68b3de;
display: none;
font-size: 13px;
height: 160px;
left: 50%;
margin-left: -110px;
padding: 20px;
position: absolute;
width: 180px;
}
.gave a {
background: #f06363 none repeat scroll 0 0;
border-radius: 50%;
color: #fff !important;
display: inline-block;
font-size: 18px;
height: 75px;
line-height: 75px;
text-align: center;
width: 75px;
text-decoration: none;
}
.gave .code > img {
height: 124px;
width: 124px;
border: medium none;
max-width: 100%;
}
</style>

在模板文章的頁面如footer.php中添加如下js:

復(fù)制代碼
代碼如下:
<script type="text/javascript">
document.getElementById('gave').onmouseover = function() {
document.getElementById('wechatCode').style.display = 'block';
}
document.getElementById('gave').onmouseout = function() {
document.getElementById('wechatCode').style.display = 'none';
}
</script>

這樣就OK了。

別忘了把微信支付二維碼替換成自己的哦。

其實(shí)更好的方式是做成WordPress插件的形式,沒時(shí)間折騰,有空可以構(gòu)想一下用插件實(shí)現(xiàn),這樣可以方便大家直接安裝了。

方法二、超級(jí)簡(jiǎn)單就像文章下面所說沒技術(shù)就這樣來設(shè)置。

本人技術(shù)有限,沒有做虎嗅那種按鈕形式。我是直接在WordPress模板中添加代碼,一勞永逸,這樣就不用每次寫文章都要粘貼復(fù)制一遍代碼。本文的同時(shí)顯示微信支付和支付寶的二維碼,虎嗅只顯示一種支付碼,相信不是所有人都用微信支付或支付寶吧,所以多一種選擇多一個(gè)收入渠道。不過這適用于像我這種全站只是我一個(gè)人寫文章的。樣式參考文章正文內(nèi)容下方。

方法:

1.修改相應(yīng)風(fēng)格模板的single.php 文件

2.找到

代碼 1  <!-- END .entry-content -->

在上行添加如下代碼:


復(fù)制代碼
代碼如下:
<div style="text-align: center;"><strong>用<span style="color: #339966;">微信</span> OR <span style="color: #337fe5;">支付寶</span> 掃描二維碼</strong></div> <div style="text-align: center;"><strong>為本文作者 <span style="color: #ff6600;">打個(gè)賞</span></strong></div> <div align="center"><img class="wp-image-558 size-thumbnail" src="微信二維碼圖片地址" alt="pay_weixin" width="150" height="150" /><img class="wp-image-558 size-thumbnail" src="支付寶二維碼地址" alt="pay_weixin" width="150" height="150" /></div> <div style="text-align: center;"><span style="color: #999999;">金額隨意 快來“打”我呀~</span></div>

3.修改后保存上傳即可,當(dāng)然你也可以根據(jù)你的喜好選擇將此段代碼放置到何處.

希望本文所述對(duì)大家基于wordpress的程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論