WordPress免插件代码版给文章添加自动生成二维码功能

为wordpress文章自动生成二维码该功能实现实际很简单,直接调用自动生成二维码网站的API接口即可,再加上CSS样式即可完成。

[qgg_cyan]示例[/qgg_cyan]

将下面代码添加到主题single模板的适当位置即可。

1、Goqr.Me,国外一家专业的二维码在线生成网站,API接口调用代码如下:

<img src="http://api.qrserver.com/v1/create-qr-code/?size=150x150&data=<?php the_permalink(); ?>" alt="<?php the_title(); ?>"/>
2、联图网(liantu.com),国内一家基于http协议的免费二维码开放平台,API接口调用代码如下:
<img src="http://qr.liantu.com/api.php?w=200text=<?php the_permalink(); ?>" alt="<?php the_title(); ?>"/>

3、Google Chart API,谷歌的产品就不用多说了吧,API接口调用代码如下:

<img src="http://chart.apis.google.com/chart?cht=qr&chld=|0&choe=UTF-8&chs=150x150&chl=<?php the_permalink(); ?>" alt="<?php the_title(); ?>"/>

使用上面的代码可以在所有文章页面指定位置生成二维码图片,包括已发布的文章页面。API接口的调用不一定非要放在文章页面中,完全可以根据需要为调用代码设置指定参数,在网站所需要的任何位置生成二维码图片。

使用以上代码生成的二维码还不能完全适应我们的文章,所以需要我们在img标签中添加控制长度和宽度的元素:height=”100″ width=”100″。

本站使用的是dux主题,在正在使用的主题目录下,找到single.php,搜索

<span class="item"><?php edit_post_link('[编辑]'); ?></span>

在所在行之前添加如下完整代码:

<!--扫描二维码--> <span class="item"><a style="cursor : pointer;" onmouseover="document.all.qr.style.visibility=''" onmouseout="document.all.qr.style.visibility='hidden'">扫描二维码</a> <span id="qr" style="visibility: hidden;"><img style="position:absolute;z-index:99999;" height="100" width="100" src="https://api.qrserver.com/v1/create-qr-code/?size=150x150&data==<?php the_permalink(); ?>" alt="<?php the_title(); ?>"/></span></span>
修改完成之后覆盖上传即可。

版权声明:
作者:水东柳
链接:https://shuidl.com/1925.html
来源:水东柳博客
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
打赏
< <上一篇
下一篇>>