• 225阅读
  • 1回复

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

楼层直达
织梦dedecms首页文章列表无刷新实现时时顶、踩的方法[font=&quot] ueWG/`ig  
Pq_Il9  
第一步:首先创建一个空白首页文件,在里面<body>区域加入以下调用代码: x b_C1n  
<ol> :*oI"U*f  
{dede:arclist row=’5′ titlelen=’20′} W)9KYI9u  
<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> awC&xVf  
<script language=”javascript” type=”text/javascript”>getDigg([field:id/]);</script> 6,c,i;J_  
{/dede:arclist} iSsy_ |  
</ol> FS@SC`~(  
这里的<script language=”javascript” type=”text/javascript”>getDigg([field:id/]);</script> 被加在了arclist标签里作为底层模板,是为了让每一篇文档都可以独立显示其顶和踩的状态。 atN`w=6A`  
]X-ZRmB`  
第二步:在<head></head>区域内加入以下代码: NGxii$F  
<script language=”javascript” type=”text/javascript” src=”{dede:global.cfg_cmsurl/}/include/dedeajax2.js”></script> h+Z|s  
<script language=”javascript” type=”text/javascript”> -l,ib=ne  
function postDigg(ftype,aid) Ar):D#D  
{ 0[hl&7 Ab@  
var taget_obj = document.getElementById(‘diggNum’+aid); p 3_Q  
var saveid = GetCookie(‘diggid’); {{ wVM:1  
if(saveid != null) =1esUO[nx  
{ Gu%`__   
var saveidsaveids = saveid.split(‘,’); \?C(fp R  
var hasid = false; i3Ffk+ |b  
saveid = ”; APLu?wy7s5  
j = 1; F-=er e  
for(i=saveids.length-1;i>=0;i–) e EU :  
{ (Bmjz*%M  
if(saveids==aid && hasid) continue; "?N`9J|j)~  
else { qrdA?V V  
if(saveids==aid && !hasid) hasid = true; c/hml4  
saveid += (saveid==” ? saveids : ‘,’+saveids); ZRX>SyM  
j++; 0CDTj,eK  
if(j==20 && hasid) break; $OUa3!U_!  
if(j==19 && !hasid) break; ", |wG7N K  
} h`vM+,I  
} ]-AT(L >  
if(hasid) { alert(“您已经顶过该帖,请不要重复顶帖!”); return; } tRXM8't   
else saveid += ‘,’+aid; ,Tr12#D:  
SetCookie(‘diggid’,saveid,1); "jpjBH:c$  
} ^< E,aCy  
else fx}R7GN2  
{ L@2H>Lh35  
SetCookie(‘diggid’,aid,1); b ;}MA7=  
} .*zQ\P  
myajax = new DedeAjax(taget_obj,false,false,”,”,”); =* (d+[_  
var url = “{dede:global.cfg_phpurl/}/digg_ajax_index.php?action=”+ftype+”id=”+aid; Onc!5L  
myajax.SendGet2(url); 2dq{n.cgs  
DedeXHTTP = null; (Q'XjN\#  
} m83i6"!H  
function getDigg(aid) \u)(+t{  
{ V~+Unn  
var taget_obj = document.getElementById(‘diggNum’+aid); _{ba  
myajax = new DedeAjax(taget_obj,false,false,”,”,”); gr S,PKH  
myajax.SendGet2(“{dede:global.cfg_phpurl/}/digg_ajax_index.php?id=”+aid); UtWoSFZ'o!  
DedeXHTTP = null; 6-JnT_  
} bX9}G#+U  
</script> 59ivL6=3  
这一段代码主要就是引入织梦系统自带的Ajax框架(dedeajax2.js)和两个操作的函数(postDigg(ftype,aid)与getDigg(aid)) eR}d"F4W  
Ft|a/e  
第三步:在/plus/ 文件夹下创建一个名为digg_ajax_index.php的文件,该文件的内容为: -p)HH@6a  
<?php/** * CMS集中营 www.cmsjzy.cn */ 9S<W~# zz  
require_once(dirname(__FILE__).”/../include/common.inc.php”); %_ z]iz4  
$action = isset($action) ? trim($action) : ”; s9'iHe  
$id = emptyempty($id)? 0 : intval(preg_replace(“/[^\d]/”,”, $id)); T|}HK]QOX  
if($id < 1) #F9$"L1Hg  
{ 6F<L4*4U  
exit(); ]xS< \{og  
} ~f@;.  
$maintable = ‘dede_archives’; F>}).qx  
if($action == ‘good’) lz>5bR'  
{ J7$=f~$  
$dsql->ExecuteNoneQuery(“Update `$maintable` set scores = scores + {$cfg_caicai_add},goodpost=goodpost+1,lastpost=”.time().” where id=’$id’”); Gm|QOuw  
} l p? h~  
else if($action==’bad’) Npu;f>g0_  
{ 7_{x '#7  
$dsql->ExecuteNoneQuery(“Update `$maintable` set scores = scores – {$cfg_caicai_sub},badpost=badpost+1,lastpost=”.time().” where id=’$id’”); CHLMY}O0  
} "W1q}4_  
$digg = ”; 2AlLcfAW  
$row = $dsql->GetOne(“Select goodpost,badpost,scores From `$maintable` where id=’$id’ “); 5i#B?+Y  
if(!is_array($row)) xWlB!r<}Gz  
{ OrH&dY  
exit(); ) wGC=,  
} -&HN h\  
if($row['goodpost']+$row['badpost'] == 0) 8C YJR/  
{ 4RzG3CJdS  
$row['goodper'] = $row['badper'] = 0; GY4yZa  
} ElYHA  
else %+'&$  
{ kQ:2@SOm  
$row['goodper'] = number_format($row['goodpost']/($row['goodpost']+$row['badpost']),3)*100; Y>z(F\  
$row['badper'] = 100-$row['goodper']; Rc6Rk!^  
} D@3|nS  
if(emptyempty($formurl)) $formurl = ”; q2SkkY$_]y  
if($formurl==’caicai’) ;J`X0Vl$  
{ ]f-e/8$`@  
if($action == ‘good’) $digg = $row['goodpost']; |e\:0O?  
if($action == ‘bad’) $digg = $row['badpost']; *yJb4uALB  
} $4?%Z>'  
else vi=yR  
{ UjfB+=7I{L  
$row['goodper'] = trim(sprintf(“%4.2f”, $row['goodper'])); >:K3y$]_  
$row['badper'] = trim(sprintf(“%4.2f”, $row['badper'])); 7>4t{aRf_8  
$digg = ‘操作区:<a href=”javascript:” onclick=”javascript:postDigg(\’good\’,’.$id.’)”>顶</a>(’.$row['goodpost'].’) <a href=”javascript:” onclick=”javascript:postDigg(\’bad\’,’.$id.’)”>踩</a>(’.$row['badpost'].’)’; x r=f9?%R  
} . XY'l  
AjaxHead(); Mu:H'$"'H  
echo $digg; >LNl8X:Cz*  
exit(); ^X?[zc GE  
?>
安逸关键词: tag
只看该作者 安逸沙发  发表于: 06-23
我们在仿站的过程中。经常会遇到需要调用多个指定的顶级栏目导航,那我们如何实现呢?本文来讲解一下指定导航栏显示的方法: JIw?]xa*  
^n<YO=|u  
{dede:channelartlist row='2' typeid='1,2这里输入多个指定的栏目ID' } U}DE9e{/!  
<li><a href='{dede:field name='typeurl'/}'>{dede:field name='typename'/}</a></li> fMUh\u3  
{/dede:channelartlist}
快速回复

限100 字节
安逸网提示:如果您在写长篇帖子又不马上发表,建议存为草稿
 
认证码:
上一个 下一个