• 156阅读
  • 1回复

织梦dedecms首页文章列表无刷新实现时时顶、踩的方法

楼层直达
织梦dedecms首页文章列表无刷新实现时时顶、踩的方法[font=&quot] J_yXL7d  
UB>BVBCt  
第一步:首先创建一个空白首页文件,在里面<body>区域加入以下调用代码: 7J6Z?  
<ol> g<^A(zM  
{dede:arclist row=’5′ titlelen=’20′} .C+(E@eyA  
<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> 4DL2 A;T  
<script language=”javascript” type=”text/javascript”>getDigg([field:id/]);</script> * Z)j"i  
{/dede:arclist} $g VbeQ  
</ol> H ~fF; I  
这里的<script language=”javascript” type=”text/javascript”>getDigg([field:id/]);</script> 被加在了arclist标签里作为底层模板,是为了让每一篇文档都可以独立显示其顶和踩的状态。 @aFk|.6  
`) ],FE*:  
第二步:在<head></head>区域内加入以下代码: 9qGba=}Ey  
<script language=”javascript” type=”text/javascript” src=”{dede:global.cfg_cmsurl/}/include/dedeajax2.js”></script> GZx*A S]+  
<script language=”javascript” type=”text/javascript”> csJ)Pt?d  
function postDigg(ftype,aid) :?ZrD,D  
{ y>h9:q|  
var taget_obj = document.getElementById(‘diggNum’+aid); /D|q-`*K  
var saveid = GetCookie(‘diggid’); (igB'S5wf  
if(saveid != null) ?5};ONjN  
{ U6H3T0#  
var saveidsaveids = saveid.split(‘,’); NZ8X@|N  
var hasid = false; )ryP K"V  
saveid = ”; -U_,RMw~  
j = 1; suWO:]FR  
for(i=saveids.length-1;i>=0;i–) t"J{qfNs  
{ ?uJX  
if(saveids==aid && hasid) continue; :w|=o9J  
else { bF,.6iKI  
if(saveids==aid && !hasid) hasid = true; ?-9uf\2_  
saveid += (saveid==” ? saveids : ‘,’+saveids); o >yXEg  
j++; d, ?GW  
if(j==20 && hasid) break; ?Oy0p8  
if(j==19 && !hasid) break; cud9oJ-=;  
} c (5XT[Tw  
} DC BN89#  
if(hasid) { alert(“您已经顶过该帖,请不要重复顶帖!”); return; } [C;Neslo  
else saveid += ‘,’+aid; (LXYx<  
SetCookie(‘diggid’,saveid,1); y[AB,Dd  
} ln , 9v  
else [[N${C  
{ Gp)J[8j  
SetCookie(‘diggid’,aid,1); BOy&3.h5?  
} <_=O0 t| 6  
myajax = new DedeAjax(taget_obj,false,false,”,”,”); b<"jmB{  
var url = “{dede:global.cfg_phpurl/}/digg_ajax_index.php?action=”+ftype+”id=”+aid; v Lq%k+D#  
myajax.SendGet2(url); Wy-y-wi:p  
DedeXHTTP = null; d`5AQfL&  
} o"A)t=  
function getDigg(aid) &u6n5-!v  
{ !yq98I'  
var taget_obj = document.getElementById(‘diggNum’+aid); oj'YDQ^uj  
myajax = new DedeAjax(taget_obj,false,false,”,”,”); 31e O2|7  
myajax.SendGet2(“{dede:global.cfg_phpurl/}/digg_ajax_index.php?id=”+aid); )z4eRs F|  
DedeXHTTP = null; 7 &%#bMnw  
} ,Sy& ?t}`  
</script> OZ"76|H1`  
这一段代码主要就是引入织梦系统自带的Ajax框架(dedeajax2.js)和两个操作的函数(postDigg(ftype,aid)与getDigg(aid)) R2 J A(Hn  
mV4gw'.;7  
第三步:在/plus/ 文件夹下创建一个名为digg_ajax_index.php的文件,该文件的内容为: E?BF8t_fTE  
<?php/** * CMS集中营 www.cmsjzy.cn */ S0r+Y0J]<  
require_once(dirname(__FILE__).”/../include/common.inc.php”); e:.?T\  
$action = isset($action) ? trim($action) : ”; E_Y!in 70  
$id = emptyempty($id)? 0 : intval(preg_replace(“/[^\d]/”,”, $id)); "sY}@Q7  
if($id < 1) @qx$b~%  
{ .4$F~!aj9  
exit(); )vVf- zU  
} v.u 5%  
$maintable = ‘dede_archives’; C>,> _  
if($action == ‘good’) @'?gan#(  
{ $MfRw  
$dsql->ExecuteNoneQuery(“Update `$maintable` set scores = scores + {$cfg_caicai_add},goodpost=goodpost+1,lastpost=”.time().” where id=’$id’”); u$(ei2f  
} UA ]fKi  
else if($action==’bad’) 49}WJC7 )  
{ , `EOJ"|  
$dsql->ExecuteNoneQuery(“Update `$maintable` set scores = scores – {$cfg_caicai_sub},badpost=badpost+1,lastpost=”.time().” where id=’$id’”); Yw5-:w0f  
} AP1ZIc6  
$digg = ”; X-TGrdoX  
$row = $dsql->GetOne(“Select goodpost,badpost,scores From `$maintable` where id=’$id’ “); PDCb(5  
if(!is_array($row)) Y> }\'$\b  
{ 9$C?)XKXB  
exit(); UK*v\TMv  
} 83{P7PBQ;]  
if($row['goodpost']+$row['badpost'] == 0) >+Iph2]  
{ .jtv Hr}U  
$row['goodper'] = $row['badper'] = 0; DQ c\[Gq&  
} s@y;b0$gk  
else w9O!L9 6  
{ W|uRQA`  
$row['goodper'] = number_format($row['goodpost']/($row['goodpost']+$row['badpost']),3)*100; Q6e7Z-8  
$row['badper'] = 100-$row['goodper']; 1\Pjz Lj  
} #M+_Lk3  
if(emptyempty($formurl)) $formurl = ”; .]JIo&>5  
if($formurl==’caicai’) k_zn>aR$F  
{ EN":}!E:  
if($action == ‘good’) $digg = $row['goodpost']; dga4|7-MY  
if($action == ‘bad’) $digg = $row['badpost']; kN8B,  
} "+wkruC  
else / #rH18  
{ 6-)WXJ@V  
$row['goodper'] = trim(sprintf(“%4.2f”, $row['goodper'])); wAX;)PLg  
$row['badper'] = trim(sprintf(“%4.2f”, $row['badper'])); 8e,F{>N  
$digg = ‘操作区:<a href=”javascript:” onclick=”javascript:postDigg(\’good\’,’.$id.’)”>顶</a>(’.$row['goodpost'].’) <a href=”javascript:” onclick=”javascript:postDigg(\’bad\’,’.$id.’)”>踩</a>(’.$row['badpost'].’)’; ZZTf/s*  
} .y3E @0a  
AjaxHead(); 0chpC)#Q3;  
echo $digg; n]D io  
exit(); CV\y60n  
?>
安逸关键词: tag
只看该作者 安逸沙发  发表于: 06-23
我们在仿站的过程中。经常会遇到需要调用多个指定的顶级栏目导航,那我们如何实现呢?本文来讲解一下指定导航栏显示的方法: Lc<v4Bp  
Q:6i 3 Nr/  
{dede:channelartlist row='2' typeid='1,2这里输入多个指定的栏目ID' } .</`#   
<li><a href='{dede:field name='typeurl'/}'>{dede:field name='typename'/}</a></li> Z= P]UD  
{/dede:channelartlist}
快速回复

限100 字节
安逸网提示:如果您提交过一次失败了,可以用”恢复数据”来恢复帖子内容
 
认证码:
上一个 下一个