我想要在dedecms里面实现以下功能,请大神帮我写一段代码,用dedecms标签或者自定义标签。
导航代码
{dede:channel type='self' typeid ='栏目ID'}<a href='[field:typelink/]'>[field:typename/]</a>
{/dede:channel}
列表代码
{dede:arclist typeid=1 row=20 channelid=2 col=5 titlelen=20 orderby='pubdate' imgwidth=160 imgheight=123}
<table cellspacing=2 cellpadding=0 width="98%" border=0>
<tbody>
<tr>
<td align=middle>[field:imglink/]</td></tr>
<tr>
<td align=middle>[field:textlink/]</td></tr></tbody></table>
{/dede:arclist}
按理说你复制来的代码应该是有效的,看代码调用了一个javascript方法,是不是javascript文件没有加载完整?
这是我调用的方法:
HTML部分:
<div class="newdigg" id="newdigg"><div class="diggbox digg_good" onmousemove="thisstylebackgroundPosition='left bottom';" onmouseout="thisstylebackgroundPosition='left top';" onclick="javascript:postDigg('good',38)">
<div class="digg_act">顶一下</div>
<div class="digg_num">(0)</div>
<div class="digg_percent">
<div class="digg_percent_bar"><span style="width:0%"></span></div>
<div class="digg_percent_num">0%</div>
</div>
</div>
<div class="diggbox digg_bad" onmousemove="thisstylebackgroundPosition='right bottom';" onmouseout="thisstylebackgroundPosition='right top';" onclick="javascript:postDigg('bad',38)">
<div class="digg_act">踩一下</div>
<div class="digg_num">(0)</div>
<div class="digg_percent">
<div class="digg_percent_bar"><span style="width:0%"></span></div>
<div class="digg_percent_num">0%</div>
</div>
</div>
</div>
<script language="javascript">getDigg(38);</script>
JS部分:
function postDigg(ftype,aid){
var taget_obj = documentgetElementById('newdigg');
var saveid = GetCookie('diggid');
if(saveid != null)
{
var saveids = saveidsplit(',');
var hasid = false;
saveid = '';
j = 1;
for(i=saveidslength-1;i>=0;i--)
{
if(saveids[i]==aid && hasid) continue;
else {
if(saveids[i]==aid && !hasid) hasid = true;
saveid += (saveid=='' saveids[i] : ','+saveids[i]);
j++;
if(j==20 && hasid) break;
if(j==19 && !hasid) break;
}
}
if(hasid) { alert("您已经顶过该帖,请不要重复顶帖 !"); return; }
else saveid += ','+aid;
SetCookie('diggid',saveid,1);
}
else
{
SetCookie('diggid',aid,1);
}
myajax = new DedeAjax(taget_obj,false,false,'','','');
var url = "/plus/digg_ajaxphpaction="+ftype+"&id="+aid;
myajaxSendGet2(url);
DedeXHTTP = null;
}
function getDigg(aid)
{
var taget_obj = documentgetElementById('newdigg');
myajax = new DedeAjax(taget_obj,false,false,'','','');
myajaxSendGet2("/plus/digg_ajaxphpid="+aid);
DedeXHTTP = null;
}
确保加载了JS文件:
<script language="javascript" type="text/javascript" src="/include/dedeajax2js"></script>
在\dede\include\extendfuncphp文件中添加如下函数:
function getArticleList($category=0,$order="",$limit="0,200"){
global $dsql;
$query = "SELECT arc,tptypedir,tptypename,tpcorank,tpisdefault,tpdefaultname,tpnamerule,
tpnamerule2,tpispart,tpmoresite,tpsiteurl,tpsitepath
FROM `#@__archives` arc LEFT JOIN `#@__arctype` tp on arctypeid=tpid
where tpid=$category";
//此sql语句我只加了where判断文章所属分类
//其他的order limit 你根据需要自己添加
$dsql->SetQuery($query);
$dsql->Execute('lit');
$arr = array();
$cnt = 0;
$str = "";
while ($row = $dsql->GetArray('lit')) {
if($cnt%4 == 0){
$str = "<div class='css1'>";
}
if($cnt%4 > 0){
$class = "css3";
}else{
$class = "css2";
}
$str = "<span class='"$class"'>"$row['title']"</span>";
$cnt++;
if($cnt%4 == 0){
$str = "</div>";
}
//$row中可用的常用字段如下:$row['id'],$row['typeid'],$row['senddate'],$row['title'],$row['ismake'], row['arcrank'],$row['namerule'],$row['typedir'],$row['money'],$row['filename'],$row['moresite'],$row['siteurl'],$row['sitepath']
}
return $str;
}
然后在模板中使用
{dede:field name='typeid' function="getArticleList(@me)" /}
将分类的id传给此函数就可以调用到数据,输出就是你要的格式。
输出内容你修改下php文件,常用字段都给你写在注释里了。
如果可以请也将我昨天给你回答的采纳一下。
{dede:channel type="son" typeid="3" row="52" col="13"}
中的row="52" 修改成你实际想要调用的的条数,如1,2,3,4,5……
0条评论