• 全国400电话网上服务平台
    强大号码库资源任选,方便,快捷,快速开通。
    咨询热线:400-1100-266  

    织梦dedecms首页文章列表无刷新实现时时顶、踩的
    POST TIME:2017-11-13 00:11
    织梦dedecms首页文章列表无刷新实现时时顶、踩的方法
    第一步:首先创建一个空白首页文件,在里面<body>区域加入以下调用代码:
    <ol>
    {dede:arclist row=’5′ titlelen=’20′}
    <li><a href=”[field:arcurl/]“>[field:title/]</a> <span id=”diggNum[field:id/]“>操作区:<a href=”javascript:” onclick=”javascript:postDigg(‘good’,[field:id/])”>顶</a>([field:goodpost/]) <a href=”javascript:” onclick=”javascript:postDigg(‘bad’,[field:id/])”>踩</a>([field:badpost/])</span></li>
    <script language=”javascript” type=”text/javascript”>getDigg([field:id/]);</script>
    {/dede:arclist}
    </ol>
    这里的<script language=”javascript” type=”text/javascript”>getDigg([field:id/]);</script> 被加在了arclist标签里作为底层模板,是为了让每一篇文档都可以独立显示其顶和踩的状态。
    第二步:在<head></head>区域内加入以下代码:
    <script language=”javascript” type=”text/javascript” src=”{dede:global.cfg_cmsurl/}/include/dedeajax2.js”></script>
    <script language=”javascript” type=”text/javascript”>
    function postDigg(ftype,aid)
    {
    var taget_obj = document.getElementById(‘diggNum’+aid);
    var saveid = GetCookie(‘diggid’);
    if(saveid != null)
    {
    var saveidsaveids = 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(“您已经顶过该帖,请不要重复顶帖!”); return; }
    else saveid += ‘,’+aid;
    SetCookie(‘diggid’,saveid,1);
    }
    else
    {
    SetCookie(‘diggid’,aid,1);
    }
    myajax = new DedeAjax(taget_obj,false,false,”,”,”);
    var url = “{dede:global.cfg_phpurl/}/digg_ajax_index.php?action=”+ftype+”id=”+aid;
    myajax.SendGet2(url);
    DedeXHTTP = null;
    }
    function getDigg(aid)
    {
    var taget_obj = document.getElementById(‘diggNum’+aid);
    myajax = new DedeAjax(taget_obj,false,false,”,”,”);
    myajax.SendGet2(“{dede:global.cfg_phpurl/}/digg_ajax_index.php?id=”+aid);
    DedeXHTTP = null;
    }
    </script>
    这一段代码主要就是引入织梦系统自带的Ajax框架(dedeajax2.js)和两个操作的函数(postDigg(ftype,aid)与getDigg(aid))
    第三步:在/plus/文件夹下创建一个名为digg_ajax_index.php的文件,该文件的内容为:
    <?php
    /**
    * CMS集中营 www.cmsjzy.cn
    */
    require_once(dirname(__FILE__).”/../include/common.inc.php”);
    $action = isset($action) ? trim($action) : ”;
    $id = emptyempty($id)? 0 : intval(preg_replace(“/[^\d]/”,”, $id));
    if($id < 1)
    {
    exit();
    }
    $maintable = ‘dede_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(emptyempty($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 href=”javascript:” onclick=”javascript:postDigg(\&;good\&;,’.$id.’)”>顶</a>(’.$row['goodpost'].’) <a href=”javascript:” onclick=”javascript:postDigg(\&;bad\&;,’.$id.’)”>踩</a>(’.$row['badpost'].’)’;
    }
    AjaxHead();
    echo $digg;
    exit();
    ?>
    
    Copyright © 2003-2016
    时间:9:00-21:00 (节假日不休)
    版权所有:巨人网络(扬州)科技有限公司
    总部地址:江苏省信息产业基地11号楼四层
    《增值电信业务经营许可证》 苏B2-20120278
    X

    截屏,微信识别二维码

    微信号:veteran88

    (点击微信号复制,添加好友)

     打开微信

    微信号已复制,请打开微信添加咨询详情!