描述:当下曾经热门的国内第三方社区化分享工具基本已经全部停止了服务,如百度分享,目前网站还能访问的似乎只有bshare了,但是也已经处在停止维护的状态,分享工具也几乎是不能正常使用的情况。那如果确实需要添加文章分享功能该怎么办呢?可以申请相关网站的api接口来开发,或者使用相关的URL分享链接自己添加,下…
当下曾经热门的国内第三方社区化分享工具基本已经全部停止了服务,如百度分享,目前网站还能访问的似乎只有bshare了,但是也已经处在停止维护的状态,分享工具也几乎是不能正常使用的情况。那如果确实需要添加文章分享功能该怎么办呢?可以申请相关网站的api接口来开发,或者使用相关的URL分享链接自己添加,下面源码库整理的给Z-Blog文章添加新浪微博、QQ空间和微信的分享按钮代码的教程步骤。
PS:如果没有特点说明,下文中提到的“编辑主题”均指编辑网站当前正在使用的那个主题。
1、编辑主题的 post-single.php 文件(通用是这个文件,如果不是请在 single.php 查看调用的哪个),找到代码
{$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三个是对应微信、QQ空间、微博的图标图片,源码库不提供,可以在 iconfont网站上找来下载,然后上传到主题的style/images/目录
3、在下面的网址中下载用于生成文章二维码的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" href="https://123vo.cn/tag/451.html" >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" href="https://123vo.cn/tag/451.html" >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}
保存文件后,进入网站后台首页,点击“清空缓存并重新编译模板”后,打开网站文章就有分享按钮了。
pbootcms内核开发的网站模板,该模板适用于微信小程序网站、软件开发网站等企业,当然其他行业也可以做,只需要把文字图片换成其他行业的即可;PC+WAP,同一个后台,数据即时同步,简单适用!附带测试数据!友好的seo,所有页面均都能完全自定义标题/关键词/描述,PHP程序,安全、稳定、快速;用低成…
(PC+WAP)粉色家政服务公司网站模板 月嫂保姆网站源码下载pbootcms内核开发的网站模板,该模板适用于家政服务公司网站、月嫂保姆网站等企业,当然其他行业也可以做,只需要把文字图片换成其他行业的即可;PC+WAP,同一个后台,数据即时同步,简单适用!附带测试数据!友好的seo,所有页…
(PC+WAP)红色火锅加盟网站pbootcms模板 餐饮美食网站源码下载pbootcms内核开发的网站模板,该模板适用于火锅加盟网站、餐饮美食网站等企业,当然其他行业也可以做,只需要把文字图片换成其他行业的即可;PC+WAP,同一个后台,数据即时同步,简单适用!附带测试数据!友好的seo,所有页面…
(PC+WAP)绿色草坪地坪施工pbootcms网站模板 操场人造草坪网站源码下载pbootcms内核开发的网站模板,该模板适用于人造草坪网站、草坪地坪网站等企业,当然其他行业也可以做,只需要把文字图片换成其他行业的即可;PC+WAP,同一个后台,数据即时同步,简单适用!附带测试数据!友好的seo,…
本套织梦模板采用织梦最新内核开发的模板,这款模板使用范围广,不仅仅局限于一类型的企业,政府部门、单位机构类的网站都可以用该模板。你只需要把图片和文章内容换成你的即可,颜色都可以修改,改完让你耳目一新的感觉!布局规整,利于用户体验,手工书写DIV+CSS,代码精简。同一个后台管理 三网合一简…
简介:104套官网源码静态html页面APP下载页面HTML源码,多年收藏精品HTML官网源码104套所有行业均可修改使用。人工精选源码每一套都是精品,纯静态页面无后台下载连接(复制直接下载)https://wp.123vo.cn/index/share/code/jq2ENvLPb1内容看完了…