因为自己的网站是DedeCMS架构的,实现起来比WordPress博客要复杂一些,织梦58参考了一下DedeCMS自己带的点赞功能,发现已经十分完善,织梦58就直接借鉴过来加以扩展,加了一个打赏的二维码,实现了自己博客文章页的点赞+打赏功能,效果如下图:
接下来,织梦58把具体实现的方法写出来,希望能对大家有所帮助。
一、js引用
实现点赞功能需要引用系统已有的js文件,这个文件位置为:/include/dedeajax2.js ,引用代码为:
将这段代码放在DedeCMS当前使用主题文章页模版的部分即可。缓存点击数和判断当前是否点击过的判断js代码为: |
这段代码紧跟dedeajax2.js调用语句后面。
注:余斗使用的DedeCMS版本为V5.7 SP1正式版,而DedeCMSV5.5版本以后都自带dedeajax2.js 这个文件。
二、点赞/踩html代码
将以下代码放入要显示点赞和踩的位置(一般都是文章页调用文章正文代码{dede:field.body /}后)
三、css样式
将以下css代码加入到文章页模版的css文件中:
#newdigg{border-bottom:medium none;padding:5px 0;}
.social-main{margin:10px auto;position:relative;width:283px;height:40px}
.social-main a{border-radius:2px;color:#fff;float:left;line-height:35px;text-align:center}
.social-main a:hover{background:#878787 none repeat scroll 0 0;transition:all .2s ease-in 0s}
.like a{background:#e15782 none repeat scroll 0 0;display:block;width:140px}
.shang a{background:#5ea51b none repeat scroll 0 0;border:4px solid #fff;border-radius:40px;font-size:18px;font-weight:600;height:50px;left:115px;line-height:45px;position:absolute;top:-7px;width:50px}
.bad a{background:#37ccca none repeat scroll 0 0;display:block;width:140px}
.cpa{padding-left:10px;}
.shang a:hover .s_in ,.shang a:hover .s_arrow ,.shang a:hover .s_img{display:block;}
.s_img{display:none;position:relative;background:#fff none repeat scroll 0 0;border-radius:5px;border: 1px solid #ddd;padding: 10px 10px 2px;width: 246px;top:18px;right:113px;}
.s_arrow {display:none;position: absolute; right:10px;top:35px; width: 0; height: 0; font-size: 0; border-width:16px; border-style: dashed dashed solid dashed; border-color: transparent transparent #ddd transparent;}
.s_in{ display:none;position:absolute;right:-16px;top:-14px; width: 0; height: 0; font-size: 0; border-width:16px;border-color:transparent transparent #fff transparent; border-style:dashed dashed solid dashed; z-index:999; }
实现的效果为:
样式
打赏
四、提示语与html修改
点赞后提示语修改在第一步的第二段js代码中,自己找到相关的文字,修改即可。
而调用点赞的html代码中其实只有一段js而已,要修改点赞的相关html代码则要打开/plus/digg_ajax.php,找到第98行,织梦58这里的代码为:
$digg = '顶一下
('.$row['goodpost'].')
赏
踩一下('.$row['badpost'].')';
}
|
大家可以看到其实就是用js调用php文件中的这段html代码实现的点赞和踩的计数功能,到这里就完美实现了DedeCMS文章页实现点赞功能,而打赏功能中,图片引用位置为/templets/yq/images/ds.png,大家可以把自己的打赏二维码上传到对应文件夹做下名字的修改即可。



