织梦列表页,支持顶(赞)和踩的功能,顶过后标红高亮显示
模板
<script language="javascript" type="text/javascript">
function postDigg(ftype,aid)
{
var taget_obj = document.getElementById('diggNum'+aid);
var saveid = GetCookie('diggid'); //我所有赞过的文章id
//alert(saveid);
if(saveid != null)
{
var saveids = saveid.split(',');
var hasid = false;
saveid = '';
j = 1;
for(i=saveids.length-1;i>=0;i--)
{
if(saveids[i]==aid && hasid) continue; //我顶过
else {
if(saveids[i]==aid && !hasid) hasid = true;
saveid += (saveid=='' ? saveids[i] : ','+saveids[i]);
j++;
if(j==20 && hasid) break;
if(j==19 && !hasid) break;
}
}
if(hasid) {
//alert("您已经顶过该帖,请不要重复顶帖 !");
//如果点击后,被赞过.则不需要更新统计,直接改变颜色
$('#digg'+aid).addClass("icon-heart-on");
return;
}
else saveid += ','+aid;
SetCookie('diggid',saveid,1);
}
else
{ //如果cookie中无记录,则记录
SetCookie('diggid',aid,1);
}
myajax = new DedeAjax(taget_obj,false,false,'','','');
var url = "{dede:global.cfg_phpurl/}/digg_ajax_list.php?action="+ftype+"&id="+aid;
myajax.SendGet2(url);
DedeXHTTP = null;
}
</script>
|
{dede:arclist row='6' orderby='id' titlelen='100'}
<span id="diggNum[field:id/]"> <a href="javascript:"class=" text-bbb text-16" onclick="javascript:postDigg('good',[field:id/])"><span id="digg[field:id/]" class="icon-heart2 "> </span> </a>[field:goodpost/]
</span>
{/dede:arclist}
|
css
.icon-heart2{
background: url(../images/bg-main.png) -22px 5px no-repeat;
}
.icon-heart2:hover{
background: url(../images/bg-main.png) 2px 4px no-repeat;
}
.icon-heart-on{
background: url(../images/bg-main.png) 2px 4px no-repeat;
}
|
然后在,plus中新建立一个digg_ajax_list.PHP文件,内容为
<?php
require_once(dirname(__FILE__)."/../include/common.inc.php");
$action = isset($action) ? trim($action) : '';
$id = empty($id)? 0 : intval(preg_replace("/[^\d]/",'', $id));
if($id < 1)
{
exit();
}
$maintable = 'archives';
if($action == 'good')
{
$dsql->ExecuteNoneQuery("Update `$maintable` set scores = scores + {$cfg_caicai_add},goodpost=goodpost+1,lastpost=".time()." where id='$id'");
}
else if($action=='bad')
{
$dsql->ExecuteNoneQuery("Update `$maintable` set scores = scores - {$cfg_caicai_sub},badpost=badpost+1,lastpost=".time()." where id='$id'");
}
$digg = '';
$row = $dsql->GetOne("Select goodpost,badpost,scores From `$maintable` where id='$id' ");
if(!is_array($row))
{
exit();
}
if($row['goodpost']+$row['badpost'] == 0)
{
$row['goodper'] = $row['badper'] = 0;
}
else
{
$row['goodper'] = number_format($row['goodpost']/($row['goodpost']+$row['badpost']),3)*100;
$row['badper'] = 100-$row['goodper'];
}
if(empty($formurl)) $formurl = '';
if($formurl=='caicai')
{
if($action == 'good') $digg = $row['goodpost'];
if($action == 'bad') $digg = $row['badpost'];
}
else
{
$row['goodper'] = trim(sprintf("%4.2f", $row['goodper']));
$row['badper'] = trim(sprintf("%4.2f", $row['badper']));
$digg = '<a class=" text-bbb text-16"href="javascript:" onclick="javascript:postDigg(\'good\','.$id.')"><span =id="digg'.$id.'"class="icon-heart-on"> </span> </a>'.$row['goodpost']; //点击后,如果从没有被赞过,则自动把新的点击次数重写入目标位置.
}
AjaxHead();
echo $digg;
exit();
?>
|
☉首先声明,只要是我们的vip会员所有源码均可以免费下载,不做任何限制
☉本站的源码不会像其它下载站一样植入大量的广告。为了更好的用户体验以后坚持不打水印
☉本站只提供精品源码,源码在于可用,不在多!!希望在这里找到你合适的。
☉本站提供的整站程序,均带数据及演示地址。可以在任一源码详情页查看演示地址
☉本站所有资源(包括源码、模板、素材、特效等)仅供学习与参考,请勿用于商业用途。
☉如有其他问题,请加网站客服QQ(984818011)进行交流。
☉本站的源码不会像其它下载站一样植入大量的广告。为了更好的用户体验以后坚持不打水印
☉本站只提供精品源码,源码在于可用,不在多!!希望在这里找到你合适的。
☉本站提供的整站程序,均带数据及演示地址。可以在任一源码详情页查看演示地址
☉本站所有资源(包括源码、模板、素材、特效等)仅供学习与参考,请勿用于商业用途。
☉如有其他问题,请加网站客服QQ(984818011)进行交流。
相关教程:
- 织梦dede首页列表页获取文章对应的tag标签
- 织梦dede导航栏目顶级和二级判断二级输出不同url
- 织梦dede标签array runphp静态生成乱码BUG解决方法
- 织梦dede如何禁止会员发布文章内容带超链接
- 织梦ajax跨域提交自定义表单和跨域验证码问题
- 织梦CMS MIP文章内容页图片适配百度MIP规范
- 织梦CMS时间格式实现XX秒前、XX分钟前、XX天前
- 织梦DedeCMS更新系统缓存增加清理沉余缓存的功能
- 织梦CMS让channelartlist标签支持currentstyle属性的
- 织梦dede自带编辑器替换百度ueditor编辑器
- 织梦DEDECMS整站动态化或整站静态化设置方法
- 织梦dede 模板路径templets目录都有什么?
