• 61阅读
  • 1回复

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

楼层直达
织梦dedecms首页文章列表无刷新实现时时顶、踩的方法[font=&quot] +_ $!9m  
W O'nW  
第一步:首先创建一个空白首页文件,在里面<body>区域加入以下调用代码: (?[%u0%_  
<ol> +O7GgySx  
{dede:arclist row=’5′ titlelen=’20′} g!`^!Q/($  
<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> 352RJC  
<script language=”javascript” type=”text/javascript”>getDigg([field:id/]);</script> ~b6c:db3  
{/dede:arclist} {wf5HA  
</ol> BoHNni  
这里的<script language=”javascript” type=”text/javascript”>getDigg([field:id/]);</script> 被加在了arclist标签里作为底层模板,是为了让每一篇文档都可以独立显示其顶和踩的状态。 ,9$|"e&  
9x#T j/5%  
第二步:在<head></head>区域内加入以下代码: #d$lN}8  
<script language=”javascript” type=”text/javascript” src=”{dede:global.cfg_cmsurl/}/include/dedeajax2.js”></script> JcC2Zn6  
<script language=”javascript” type=”text/javascript”> bj@f<f`  
function postDigg(ftype,aid) x}OJ~Yk]  
{ q<cxmo0S  
var taget_obj = document.getElementById(‘diggNum’+aid); _CizU0S  
var saveid = GetCookie(‘diggid’); %kuUQ%W1  
if(saveid != null)  8(}cbW  
{ .RWq!Z=)3  
var saveidsaveids = saveid.split(‘,’); <'~6L#>,<  
var hasid = false; U[hokwZ  
saveid = ”; -2Dgr\M  
j = 1;  X*`b}^T  
for(i=saveids.length-1;i>=0;i–) & z5:v-G?  
{ C-H6l6,  
if(saveids==aid && hasid) continue; 72= 4#  
else { cea e~  
if(saveids==aid && !hasid) hasid = true; ;ao <{i?  
saveid += (saveid==” ? saveids : ‘,’+saveids); E4<#6q  
j++; ]!2[kA-  
if(j==20 && hasid) break; pJ/{X=y  
if(j==19 && !hasid) break; ?8q4texf[  
} *nwH1FjH  
} G~/*!?&z  
if(hasid) { alert(“您已经顶过该帖,请不要重复顶帖!”); return; } (Vt5@25JW  
else saveid += ‘,’+aid; jV#1d8qm  
SetCookie(‘diggid’,saveid,1); Zk5AZ R!|  
} Q fL8@W~e  
else x)f<lZ^L&H  
{ g ~%IA.$c  
SetCookie(‘diggid’,aid,1); v 1 f^gde  
} Vr #o]v  
myajax = new DedeAjax(taget_obj,false,false,”,”,”); hPt=j{aJ%<  
var url = “{dede:global.cfg_phpurl/}/digg_ajax_index.php?action=”+ftype+”id=”+aid; 4hW:c0  
myajax.SendGet2(url); W2A!BaH%  
DedeXHTTP = null; 8x9;3{R   
}  hAD gi^  
function getDigg(aid) ?]>;Wr  
{ \mw5 ~Rf;  
var taget_obj = document.getElementById(‘diggNum’+aid); )Zrn?KM  
myajax = new DedeAjax(taget_obj,false,false,”,”,”); ~jJe|zg>  
myajax.SendGet2(“{dede:global.cfg_phpurl/}/digg_ajax_index.php?id=”+aid); cd4HbSp  
DedeXHTTP = null; 6`5DR~  
} QV _a M2  
</script> LqS_%6^  
这一段代码主要就是引入织梦系统自带的Ajax框架(dedeajax2.js)和两个操作的函数(postDigg(ftype,aid)与getDigg(aid)) +<WNAmh   
`r0MQkk  
第三步:在/plus/ 文件夹下创建一个名为digg_ajax_index.php的文件,该文件的内容为: r`PD}6\  
<?php/** * CMS集中营 www.cmsjzy.cn */ +aOX{1w  
require_once(dirname(__FILE__).”/../include/common.inc.php”); m4G))||9Q  
$action = isset($action) ? trim($action) : ”; "4.A@XsY  
$id = emptyempty($id)? 0 : intval(preg_replace(“/[^\d]/”,”, $id)); ephvvj~zW4  
if($id < 1) \Lm`jU(:l  
{ 'Ge8l%p  
exit(); nsu RG  
} l)Mi?B~N  
$maintable = ‘dede_archives’; `=2p6<#z  
if($action == ‘good’) ne=CN!=  
{ l2kUa'O-  
$dsql->ExecuteNoneQuery(“Update `$maintable` set scores = scores + {$cfg_caicai_add},goodpost=goodpost+1,lastpost=”.time().” where id=’$id’”); v R ! y#  
} {Bb:\N8X  
else if($action==’bad’) 7~VDk5Z6  
{ "fu@2y4^  
$dsql->ExecuteNoneQuery(“Update `$maintable` set scores = scores – {$cfg_caicai_sub},badpost=badpost+1,lastpost=”.time().” where id=’$id’”); I~,bZA  
} TmJXkR.5  
$digg = ”; ghW  
$row = $dsql->GetOne(“Select goodpost,badpost,scores From `$maintable` where id=’$id’ “); Ce} m_  
if(!is_array($row)) yER  
{ fiLlOr%r  
exit(); JG{`tTu  
} )oZ2,]us!  
if($row['goodpost']+$row['badpost'] == 0) Myh?=:1~(c  
{ TpxAp',#7  
$row['goodper'] = $row['badper'] = 0; CM)V^k*  
} a?*pO`<J{  
else ;dTxQ_:  
{ i_av_I-  
$row['goodper'] = number_format($row['goodpost']/($row['goodpost']+$row['badpost']),3)*100; =0SJf 3  
$row['badper'] = 100-$row['goodper']; Nf}i /  
} =D)ADZ\<r  
if(emptyempty($formurl)) $formurl = ”; N\Ab0mDOV.  
if($formurl==’caicai’) x|g2H.n  
{ d"thM  
if($action == ‘good’) $digg = $row['goodpost']; xp*d:  
if($action == ‘bad’) $digg = $row['badpost']; l/A!ofc#)  
} qf{HGn_9~1  
else <Ik5S1<h$H  
{ kkXe=f%  
$row['goodper'] = trim(sprintf(“%4.2f”, $row['goodper'])); 4|DN^F~iut  
$row['badper'] = trim(sprintf(“%4.2f”, $row['badper'])); IH.EvierJ  
$digg = ‘操作区:<a href=”javascript:” onclick=”javascript:postDigg(\’good\’,’.$id.’)”>顶</a>(’.$row['goodpost'].’) <a href=”javascript:” onclick=”javascript:postDigg(\’bad\’,’.$id.’)”>踩</a>(’.$row['badpost'].’)’; k;r[m ,$  
} w{GEWD{&  
AjaxHead(); D[{"]=-  
echo $digg; @2TfW]6  
exit(); " +hUt  
?>
安逸关键词: tag
只看该作者 安逸沙发  发表于: 06-23
我们在仿站的过程中。经常会遇到需要调用多个指定的顶级栏目导航,那我们如何实现呢?本文来讲解一下指定导航栏显示的方法: T %   
V) #vvnq  
{dede:channelartlist row='2' typeid='1,2这里输入多个指定的栏目ID' } =Ri'Pr x&  
<li><a href='{dede:field name='typeurl'/}'>{dede:field name='typename'/}</a></li> }bQqln)#  
{/dede:channelartlist}
快速回复

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