• 355阅读
  • 1回复

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

楼层直达
织梦dedecms首页文章列表无刷新实现时时顶、踩的方法[font=&quot] 7bT /KLU  
3bts7<K=  
第一步:首先创建一个空白首页文件,在里面<body>区域加入以下调用代码: }17bV, t  
<ol> \)R-A '*U  
{dede:arclist row=’5′ titlelen=’20′} &<h?''nCy  
<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> vYzVY\   
<script language=”javascript” type=”text/javascript”>getDigg([field:id/]);</script> ;+%Z@b%  
{/dede:arclist} {!t=n   
</ol> DMMLzS0A  
这里的<script language=”javascript” type=”text/javascript”>getDigg([field:id/]);</script> 被加在了arclist标签里作为底层模板,是为了让每一篇文档都可以独立显示其顶和踩的状态。 xt))]aH  
+H}e)1^ I  
第二步:在<head></head>区域内加入以下代码: sVoR?peQ  
<script language=”javascript” type=”text/javascript” src=”{dede:global.cfg_cmsurl/}/include/dedeajax2.js”></script> (nz}J)T&  
<script language=”javascript” type=”text/javascript”> ~ B]jV$=  
function postDigg(ftype,aid) z8tl0gd%D  
{ 0||F`24  
var taget_obj = document.getElementById(‘diggNum’+aid); GZ"/k<~0  
var saveid = GetCookie(‘diggid’); ue9h   
if(saveid != null) ^j iE9k)  
{ i;]CL[#2e`  
var saveidsaveids = saveid.split(‘,’); B^m!t7/,  
var hasid = false; 4d-q!lRpa  
saveid = ”; 0BFz7  
j = 1; ^S=cNSpC  
for(i=saveids.length-1;i>=0;i–) -lnevrl   
{ ~#t*pOC5BR  
if(saveids==aid && hasid) continue; ^$}/|d(  
else { /f]/8b g>  
if(saveids==aid && !hasid) hasid = true; U2UyN9:6F  
saveid += (saveid==” ? saveids : ‘,’+saveids); P'F~\**5  
j++; )-#i8?y3C  
if(j==20 && hasid) break; b- uZ"Kf^  
if(j==19 && !hasid) break; ~4+8p9f  
} -xTKdm D  
} Z:c*!`F  
if(hasid) { alert(“您已经顶过该帖,请不要重复顶帖!”); return; } dFMAh&:>  
else saveid += ‘,’+aid; HT-PWk>2  
SetCookie(‘diggid’,saveid,1); Pv[ykrm/  
} + "zYn!0  
else `/c@nxh  
{ 5f{wJb2  
SetCookie(‘diggid’,aid,1); S%{lJYwXt  
} F Nlx1U[  
myajax = new DedeAjax(taget_obj,false,false,”,”,”); g<a<{|  
var url = “{dede:global.cfg_phpurl/}/digg_ajax_index.php?action=”+ftype+”id=”+aid; L^x5&CCwk  
myajax.SendGet2(url); | F8]Xnds  
DedeXHTTP = null; )tCx5 9  
} .=CH!{j  
function getDigg(aid) w#rVSSXQ3  
{ hu&n=6  
var taget_obj = document.getElementById(‘diggNum’+aid); D>S8$]^Dm  
myajax = new DedeAjax(taget_obj,false,false,”,”,”); K9^"NS3  
myajax.SendGet2(“{dede:global.cfg_phpurl/}/digg_ajax_index.php?id=”+aid); ] .`_, IO  
DedeXHTTP = null; 5DUi4 Cbgy  
} Wy!uRzbBv  
</script> py=i!vb&Z%  
这一段代码主要就是引入织梦系统自带的Ajax框架(dedeajax2.js)和两个操作的函数(postDigg(ftype,aid)与getDigg(aid)) Zq^^|[)bA  
y{?Kao7Ij  
第三步:在/plus/ 文件夹下创建一个名为digg_ajax_index.php的文件,该文件的内容为: sc9]sIb  
<?php/** * CMS集中营 www.cmsjzy.cn */ z41D^}b  
require_once(dirname(__FILE__).”/../include/common.inc.php”); {x|MA(NO  
$action = isset($action) ? trim($action) : ”; n~.%p  
$id = emptyempty($id)? 0 : intval(preg_replace(“/[^\d]/”,”, $id)); y%JF8R;n  
if($id < 1) vWuyft*  
{ +<z7ds{Z  
exit(); 2nJYS2mT7  
} o16d`}/<  
$maintable = ‘dede_archives’; eXc[3ceUr  
if($action == ‘good’) " xlJs93c  
{ 9Il'E6 J  
$dsql->ExecuteNoneQuery(“Update `$maintable` set scores = scores + {$cfg_caicai_add},goodpost=goodpost+1,lastpost=”.time().” where id=’$id’”); + 2OZJVJ  
} X"wF Qa  
else if($action==’bad’) v [dAywW  
{ OW?uZ<z  
$dsql->ExecuteNoneQuery(“Update `$maintable` set scores = scores – {$cfg_caicai_sub},badpost=badpost+1,lastpost=”.time().” where id=’$id’”); >}mNi:6xq  
} 3F;EE:  
$digg = ”; S3nB:$_-;  
$row = $dsql->GetOne(“Select goodpost,badpost,scores From `$maintable` where id=’$id’ “); 9#Z zE/  
if(!is_array($row)) \ =S3 L<  
{ 87R%ke  
exit(); w' .'Yu6  
} K6ciqwUO  
if($row['goodpost']+$row['badpost'] == 0)  MK<  
{ :{x!g6bK@  
$row['goodper'] = $row['badper'] = 0; ' l|41wxk  
} LAj}kW~  
else |C^ c0  
{ 0kkRK*fp}x  
$row['goodper'] = number_format($row['goodpost']/($row['goodpost']+$row['badpost']),3)*100; &~z+R="=  
$row['badper'] = 100-$row['goodper']; cAYa=}~<  
} <Sz>ZIISd  
if(emptyempty($formurl)) $formurl = ”; 8}Fw%;Cb  
if($formurl==’caicai’) u}Lc|_ea`  
{ tq2-.]Y@U  
if($action == ‘good’) $digg = $row['goodpost']; 3| GNi~  
if($action == ‘bad’) $digg = $row['badpost']; LZgwIMd  
} K-N]h  
else 0f_66`  
{ Y:DNu9  
$row['goodper'] = trim(sprintf(“%4.2f”, $row['goodper'])); ORUWsl Mt  
$row['badper'] = trim(sprintf(“%4.2f”, $row['badper'])); a7ub.9>  
$digg = ‘操作区:<a href=”javascript:” onclick=”javascript:postDigg(\’good\’,’.$id.’)”>顶</a>(’.$row['goodpost'].’) <a href=”javascript:” onclick=”javascript:postDigg(\’bad\’,’.$id.’)”>踩</a>(’.$row['badpost'].’)’; WZfk}To1#  
} p ~,a=  
AjaxHead(); M!;`(_2  
echo $digg; 2U-#0,ll]  
exit(); Y\ #.EVz  
?>
安逸关键词: tag
只看该作者 安逸沙发  发表于: 2018-06-23
我们在仿站的过程中。经常会遇到需要调用多个指定的顶级栏目导航,那我们如何实现呢?本文来讲解一下指定导航栏显示的方法: r8qee$^M  
-V\33cA  
{dede:channelartlist row='2' typeid='1,2这里输入多个指定的栏目ID' } ]}9EBf  
<li><a href='{dede:field name='typeurl'/}'>{dede:field name='typename'/}</a></li> (Az^st/_  
{/dede:channelartlist}
快速回复

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