最近几天写文章,需要带一些连接下载功能,发现主题内的按键在经典模式下没得用,经过几天查找和验证,把我自己改良的代码分享给大家,方便使用,此改良已经改为短码显示方式,美观一些!
先看效果图吧!
把以下代码放入主题内 functions.php,zibll 的主题是放入 func.php,如果没有自己手动创建。
//定义下载按钮短代码
/*下载按钮*/
function h_down($atts, $content = null) {
extract(shortcode_atts(array(
"href" => 'http://'
) , $atts));
return '<a class="hei_down" href="' . $href . '" target="_blank" rel="nofollow"><i class="fa fa-download"></i> ' . $content . '</a>';
}
add_shortcode('hei_down', 'h_down');
//后台编辑器 短代码按键
function appthemes_add_quicktagss() {
?>
<script type="text/javascript">
//按钮
QTags.addButton( 'hei_down', '下载按键', " 点击下载", "\r" );
</script>
<?php
}
add_action('admin_print_footer_scripts', 'appthemes_add_quicktagss' );
/*结束下载按钮*/
添加完这段代码后,在传统编辑器的文本编辑框会出现一个下载按钮,在 href=” 后面的单引号中间添加你的下载地址即可。
如下图演示:已经显示的是短码,不在是很长一段代码。
添加 CSS 样式,不同主题添加的位置是不同的,有的是放入 miss.css,有的是放入 style.css,而 zibll 的是直接放到自定义 CSS 内就可以了。
/*编辑器中添加的 下载按钮&演示按钮&赞赏按钮 样式*/
.hei_down{
color:#fff;
background:#2999f7;
border-top:0;box-shadow:0 0 0 1px #EEE;border:2px solid #fff;
padding:10px 16px;
font-size:16px;
line-height:1.33;
border-radius:5px;
opacity:.8;
text-indent:0;margin-top:5px;
margin-bottom:5px;
display:inline-block;
font-weight:400;
text-align:center;
text-decoration:none;
white-space:nowrap;
vertical-align:middle;
cursor:pointer;
-webkit-user-select:none;
-moz-user-select:none;
-ms-user-select:none}
.btn-download:before{content:"\f0ed";display:inline-block;font-style:normal;font-family:FontAwesome;text-align:center;margin-right:8px}
.sg-dl{margin:20px 0 10px 0;text-align:center}
.sg-dl .sg-dl-span{margin:0 auto}
/*按键样式结束*/
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
请登录后查看评论内容