第一步:首先創(chuàng)建一個(gè)織夢(mèng)空白首頁文件,在里面<body>區(qū)域加入以下調(diào)用代碼:
<ol> {dede:arclist row=’5′ titlelen=’20′} <li><a href=”[field:arcurl/]“>[field:title/]</a> <span id=”diggNum[field:id/]“>操作區(qū):<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標(biāo)簽里作為底層模板,是為了讓每一篇文檔都可以獨(dú)立顯示其頂和踩的狀態(tài)。
第二步:在<head></head>區(qū)域內(nèi)加入以下代碼:
<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(“您已經(jīng)頂過該帖,請(qǐng)不要重復(fù)頂帖!”); 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>
這一段代碼主要就是引入織夢(mèng)系統(tǒng)自帶的Ajax框架(dedeajax2.js)和兩個(gè)操作的函數(shù)(postDigg(ftype,aid)與getDigg(aid))
第三步:在/plus/ 文件夾下創(chuàng)建一個(gè)名為digg_ajax_index.php的文件,該文件的內(nèi)容為:
<?php /** * 六久閣 www.lol9.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 = ‘操作區(qū):<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(); ?>
版權(quán)聲明: 本站資源均來自互聯(lián)網(wǎng)或會(huì)員發(fā)布,如果侵犯了您的權(quán)益請(qǐng)與我們聯(lián)系,我們將在24小時(shí)內(nèi)刪除!謝謝!
轉(zhuǎn)載請(qǐng)注明: 織夢(mèng)文章列表無刷新實(shí)現(xiàn)時(shí)時(shí)頂、踩的方法