|
织梦dedecms首页文章列表无刷新实现时时顶、踩的方法
第一步:首先创建一个空白首页文件,在里面区域加入以下调用代码:
[ol,
{dede:arclist row=’5′ titlelen=’20′}
[*,[url=,[field:title/,[/url] 操作区:[url=,顶[/url]([field:goodpost/,) [url=,踩[/url]([field:badpost/,)
{/dede:arclist}
[/ol,
这里的 被加在了arclist标签里作为底层模板,是为了让每一篇文档都可以独立显示其顶和踩的状态。
第二步:在区域内加入以下代码:
这一段代码主要就是引入织梦系统自带的Ajax框架(dedeajax2.js)和两个操作的函数(postDigg(ftype,aid)与getDigg(aid))
第三步:在/plus/ 文件夹下创建一个名为digg_ajax_index.php的文件,该文件的内容为:
require_once(dirname(__FILE__).”/../include/common.inc.php”);
$action = isset($action) ? trim($action) : ”;
$id = emptyempty($id)? 0 : intval(preg_replace(“/[^\d,/”,”, $id));
if($id
{
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 = ‘操作区:[url=,顶[/url](’.$row['goodpost',.’) [url=,踩[/url](’.$row['badpost',.’)’;
}
AjaxHead();
echo $digg;
exit();
?> |
|