document.writeln('');

在公车被猛烈进入爽文,啊灬轻点大JI巴太粗又长A片,亚洲色欲AV成人无码久久精品 ,国产大片内射1区2区,久久久网址,亚洲一区二区三区免费视频,精品欧美一区二区三区久久久,久久国产精品-久久精品

當(dāng)前位置:首頁 > 免費源碼 > zblog實現(xiàn)分享文章至微博、微信、QQ空間的代碼及添加教程

zblog實現(xiàn)分享文章至微博、微信、QQ空間的代碼及添加教程

游戲科技網(wǎng)2026年09月15日 00:50免費源碼50

當(dāng)下曾經(jīng)熱門的國內(nèi)第三方社區(qū)化分享工具基本已經(jīng)全部停止了服務(wù),如百度分享,目前網(wǎng)站還能訪問的似乎只有bshare了,但是也已經(jīng)處在停止維護(hù)的狀態(tài),分享工具也幾乎是不能正常使用的情況。那如果確實需要添加文章分享功能該怎么辦呢?可以申請相關(guān)網(wǎng)站的api接口來開發(fā),或者使用相關(guān)的URL分享鏈接自己添加,下面源碼庫整理的給Z-Blog文章添加新浪微博、QQ空間和微信的分享按鈕代碼的教程步驟。

PS:如果沒有特點說明,下文中提到的“編輯主題”均指編輯網(wǎng)站當(dāng)前正在使用的那個主題。

1、編輯主題的 post-single.php 文件(通用是這個文件,如果不是請在 single.php 查看調(diào)用的哪個),找到代碼

{$article.Content}
{$article.Content}
{$article.Content}

在其代碼上面或下面添加代碼

<div id="social-share">
<ul>
<li>
<a class="wb" href="javascript:void(0);" onclick="shareUrl(weibo);">微博</a>
</li>
<li>
<a class="wx" href="javascript:void(0);" onclick="shareUrl(weixin);">微信</a>
<div id="shareWX">
<div id="qrcode"></div>
<div class="text">
<p>使用微信掃碼二維碼</p>
<p>分享給好友或朋友圈</p>
</div>
</div>
</li>
<li>
<a class="qz" href="javascript:void(0);" onclick="shareUrl(qzone);">QQ空間</a>
</li>
</ul>
</div>
<div id="social-share">
  <ul>
      <li>
        <a class="wb" href="javascript:void(0);" onclick="shareUrl(weibo);">微博</a>
      </li>
      <li>
        <a class="wx" href="javascript:void(0);" onclick="shareUrl(weixin);">微信</a>
        <div id="shareWX">
          <div id="qrcode"></div>
          <div class="text">
            <p>使用微信掃碼二維碼</p>
            <p>分享給好友或朋友圈</p>
          </div>
        </div>
      </li>
      <li>
        <a class="qz" href="javascript:void(0);" onclick="shareUrl(qzone);">QQ空間</a>
      </li>
    </ul>
</div>
<div id="social-share"><ul><li><a class="wb" href="javascript:void(0);" onclick="shareUrl(weibo);">微博</a></li><li><a class="wx" href="javascript:void(0);" onclick="shareUrl(weixin);">微信</a><div id="shareWX"><div id="qrcode"></div><div class="text"><p>使用微信掃碼二維碼</p><p>分享給好友或朋友圈</p></div></div></li><li><a class="qz" href="javascript:void(0);" onclick="shareUrl(qzone);">QQ空間</a></li></ul></div>

2、編輯主題的樣式文件,通用是 style.css,在文本中另起一行,添加下面的代碼

#social-share {padding:20px 0;}
#social-share ul {display:flex; justify-content: center; margin:0; padding:0;}
#social-share li {padding:0 10px; position:relative; margin:0; list-style: none;}
#social-share a {display:block; width:30px; height:30px; background:no-repeat center center; background-size:contain; text-indent:-9999em; overflow: hidden;}
#social-share .wx {background-image:url(images/social_weixin.png);}
#social-share .qz {background-image:url(images/social_qzone.png);}
#social-share .wb {background-image:url(images/social_weibo.png);}
#social-share #shareWX {background-color: #fff; padding:8px; border:5px solid #666; width:130px; position:absolute; left:50%; bottom:100%; transform:translateX(-50%); margin-bottom: 10px; display: none;}
#social-share #shareWX:after {content:; display:block; border-top:10px solid #666; border-left:8px solid transparent; border-right:8px solid transparent; position:absolute; left:50%; top:100%; transform:translateX(-50%);}
#social-share #shareWX.show {display: block;}
#social-share #qrcode {padding-bottom:100%; position:relative; margin-bottom:8px;}
#social-share img {display:block; width:100%; height:100%; position:absolute; left:0; top:0;}
#social-share .text {text-align:center; font-size:12px; color:#666; line-height: 1.5em;}
#social-share {padding:20px 0;}
#social-share ul {display:flex; justify-content: center; margin:0; padding:0;}
#social-share li {padding:0 10px; position:relative; margin:0; list-style: none;}
#social-share a {display:block; width:30px; height:30px; background:no-repeat center center; background-size:contain; text-indent:-9999em; overflow: hidden;}
#social-share .wx {background-image:url(images/social_weixin.png);}
#social-share .qz {background-image:url(images/social_qzone.png);}
#social-share .wb {background-image:url(images/social_weibo.png);}
#social-share #shareWX {background-color: #fff; padding:8px; border:5px solid #666; width:130px; position:absolute; left:50%; bottom:100%; transform:translateX(-50%); margin-bottom: 10px; display: none;}
#social-share #shareWX:after {content:; display:block; border-top:10px solid #666; border-left:8px solid transparent; border-right:8px solid transparent; position:absolute; left:50%; top:100%; transform:translateX(-50%);} 
#social-share #shareWX.show {display: block;}
#social-share #qrcode {padding-bottom:100%; position:relative; margin-bottom:8px;}
#social-share img {display:block; width:100%; height:100%; position:absolute; left:0; top:0;}
#social-share .text {text-align:center; font-size:12px; color:#666; line-height: 1.5em;}
#social-share {padding:20px 0;}#social-share ul {display:flex; justify-content: center; margin:0; padding:0;}#social-share li {padding:0 10px; position:relative; margin:0; list-style: none;}#social-share a {display:block; width:30px; height:30px; background:no-repeat center center; background-size:contain; text-indent:-9999em; overflow: hidden;}#social-share .wx {background-image:url(images/social_weixin.png);}#social-share .qz {background-image:url(images/social_qzone.png);}#social-share .wb {background-image:url(images/social_weibo.png);}#social-share #shareWX {background-color: #fff; padding:8px; border:5px solid #666; width:130px; position:absolute; left:50%; bottom:100%; transform:translateX(-50%); margin-bottom: 10px; display: none;}#social-share #shareWX:after {content:; display:block; border-top:10px solid #666; border-left:8px solid transparent; border-right:8px solid transparent; position:absolute; left:50%; top:100%; transform:translateX(-50%);} #social-share #shareWX.show {display: block;}#social-share #qrcode {padding-bottom:100%; position:relative; margin-bottom:8px;}#social-share img {display:block; width:100%; height:100%; position:absolute; left:0; top:0;}#social-share .text {text-align:center; font-size:12px; color:#666; line-height: 1.5em;}

PS:social_weixin.png、social_qzone.png、social_weibo.png三個是對應(yīng)微信、QQ空間、微博的圖標(biāo)圖片,源碼庫不提供,可以在 iconfont網(wǎng)站上找來下載,然后上傳到主題的style/images/目錄

3、在下面的網(wǎng)址中下載用于生成文章二維碼的js插件 qrcode.min.js

https://github.com/davidshimjs/qrcodejs

PS:不限于這款插件,也可以使用能生成二維碼的其它js插件,把步驟 3 中的 new QRCode 方法換成其它插件的即可。

3、編輯主題的 footer.php 文件,在 </body> 上面添加下面的代碼

{if $type == article}
<script src="{$host}zb_users/theme/{$theme}/scripts/qrcode.min.js"></script>
<script type="text/javascript">
function shareUrl(social){
var _title = encodeURIComponent(document.title);
var _url = document.location;
var _pic = document.getElementsByTagName(img)[0].src;
if(social == qzone){
var _shareUrl = https://sns.qzone.<a target="_blank" title="View all posts in qq">qq</a>.com/cgi-bin/qzshare/cgi_qzshare_onekey?url= + _url + &title= + _title + &pics= + _pic + &summary=&desc=;
window.open(_shareUrl,_blank);
}else if(social == weibo){
var _shareUrl = https://service.weibo.com/share/share.php?url= + _url + &title= + _title + &pic= + _pic;
window.open(_shareUrl,_blank);
}else if(social == weixin){
if(document.getElementById(shareWX).className == ){
document.getElementById(shareWX).className = show;
new QRCode(document.getElementById(qrcode), {$article->Url});
}else{
document.getElementById(shareWX).className = ;
}
}
}
</script>
{/if}
{if $type == article}
<script src="{$host}zb_users/theme/{$theme}/scripts/qrcode.min.js"></script>
<script type="text/javascript">
function shareUrl(social){
  var _title = encodeURIComponent(document.title);
  var _url = document.location;
  var _pic = document.getElementsByTagName(img)[0].src;
  if(social == qzone){        
    var _shareUrl = https://sns.qzone.<a target="_blank"  title="View all posts in qq">qq</a>.com/cgi-bin/qzshare/cgi_qzshare_onekey?url= + _url + &title= + _title + &pics= + _pic + &summary=&desc=;
    window.open(_shareUrl,_blank);      
  }else if(social == weibo){
    var _shareUrl = https://service.weibo.com/share/share.php?url= + _url + &title= + _title + &pic= + _pic;
    window.open(_shareUrl,_blank);
  }else if(social == weixin){
 
    if(document.getElementById(shareWX).className == ){
      document.getElementById(shareWX).className = show;
      new QRCode(document.getElementById(qrcode), {$article->Url});
    }else{
      document.getElementById(shareWX).className = ;
    }
  }  
}
</script>
{/if}
{if $type == article}<script src="{$host}zb_users/theme/{$theme}/scripts/qrcode.min.js"></script><script type="text/javascript">function shareUrl(social){var _title = encodeURIComponent(document.title);var _url = document.location;var _pic = document.getElementsByTagName(img)[0].src;if(social == qzone){var _shareUrl = https://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url= + _url + &title= + _title + &pics= + _pic + &summary=&desc=;window.open(_shareUrl,_blank);}else if(social == weibo){var _shareUrl = https://service.weibo.com/share/share.php?url= + _url + &title= + _title + &pic= + _pic;window.open(_shareUrl,_blank);}else if(social == weixin){ if(document.getElementById(shareWX).className == ){document.getElementById(shareWX).className = show;new QRCode(document.getElementById(qrcode), {$article->Url});}else{document.getElementById(shareWX).className = ;}}}</script>{/if}

保存文件后,進(jìn)入網(wǎng)站后臺首頁,點擊“清空緩存并重新編譯模板”后,打開網(wǎng)站文章就有分享按鈕了。

內(nèi)容看完了