dedecms调用最新评论的文章
2013-02-06 22:31 来源:www.chinab4c.com 作者:dedecms专家
dedecms调用最新评论的文章其实是很简单的一个功能。我们知道dedecms可以很方便的处理文章以及评论。如果你想调用各个分类下对应最新评论的文章,你可以通过分类取得相关文章ID。然后去取得文章。当然了。你可以在子查询中。先检索该分类对应文章,以及该分类下文章评论对应的aid,通过文章id和aid做个联合查询,也是十分简单的事情。不过dedecms不允许子查询,所以十分纠结。
1:显现对评论和文章的标签。
function lib_newcomment(&$ctag,&$refObj)
{
global $dsql,$envs,$cfg_cmsurl;
$list = "limit|3,titlelen|10";
FillAttsDefault($ctag->CAttribute->Items , $list);
extract($ctag->CAttribute->Items);
$text = $ctag->GetInnerText();
$tcp = new DedeTagParse();
$tcp->SetNameSpace('field','[',']');
$tcp->LoadSource($text);
$typeid = trim($ctag->GetAtt('typeid'));
if(empty($typeid)) {
$typeid = ( isset($refObj->Fields['typeid']) ? $refObj->Fields['typeid'] : $envs['typeid'] );
}
$orwheres = array();
if(!empty($typeid) && $typeid != 'top')
{
//指定了多个栏目时,不再获取子类的id
if( preg_match('#,#', $typeid) )
{
//指定了getall属性或主页模板例外
if($getall==1 || empty($refObj->Fields['typeid']))
{
$typeids = explode(',', $typeid);
foreach($typeids as $ttid) {
$typeidss[] = GetSonIds($ttid);
}
$typeidStr = join(',', $typeidss);
$typeidss = explode(',', $typeidStr);
$typeidssok = array_unique($typeidss);
$typeid = join(',', $typeidssok);
}
$orwheres[] = " arc.typeid IN ($typeid) ";
}
else
{
//处理交叉栏目
$CrossID = '';
if($ctag->GetAtt('cross')=='1')
{
$arr = $dsql->GetOne("SELECT `id`,`topid`,`cross`,`crossid`,`ispart`,`typename` FROM `dede_arctype` WHERE id='$typeid' ");
if( $arr['cross']==0 || ( $arr['cross']==2 && trim($arr['crossid']=='') ) )
{
$orwheres[] = ' arc.typeid IN ('.GetSonIds($typeid).')';
}
else
{
$selquery = '';
if($arr['cross']==1) {
$selquery = "SELECT id,topid FROM `dede_arctype` WHERE typename LIKE '{$arr['typename']}' AND id<>'{$typeid}' AND topid<>'{$typeid}' ";
}
else {
$arr['crossid'] = preg_replace('#[^0-9,]#', '', trim($arr['crossid']));
if($arr['crossid']!='') $selquery = "SELECT id,topid FROM `dede_arctype` WHERE id IN('{$arr['crossid']}') AND id<>'{$typeid}' AND topid<>'{$typeid}' ";
}
if($selquery!='')
{
$dsql->SetQuery($selquery);
$dsql->Execute();
while($arr = $dsql->GetArray())
{
$CrossID .= ($CrossID=='' ? $arr['id'] : ','.$arr['id']);
}
}
}
}
if($CrossID=='') $orwheres[] = ' arc.typeid IN ('.GetSonIds($typeid).')';
else $orwheres[] = ' arc.typeid IN ('.GetSonIds($typeid).','.$CrossID.')';
}
}
$orwhere = '';
if(isset($orwheres[0])) {
$orwhere = join(' And ',$orwheres);
$orwhere = preg_replace("#^ And#is", '', $orwhere);
$orwhere = preg_replace("#And[ ]{1,}And#is", 'And ', $orwhere);
}
if($orwhere!='') $orwhere = " WHERE $orwhere ";
$sql = "select distinct(arc.aid) from dede_feedback as arc $orwhere and arc.ischeck=1 limit $limit";
$id = array();
$dsql->SetQuery($sql);
$dsql->Execute("a2");
while($row=$dsql->GetArray("a2")){
$id[] = $row['aid'];
}
$str = '';
$query = "select arc.*,tp.typedir,tp.typename,tp.corank,tp.isdefault,tp.defaultname,tp.namerule,
tp.namerule2,tp.ispart,tp.moresite,tp.siteurl,tp.sitepath
$addfieldsSql
FROM `dede_archives` arc LEFT JOIN `dede_arctype` tp on arc.typeid=tp.id
$addfieldsSqlJoin
$orwhere and arc.id in('".join("','",$id)."') $ordersql $limitsql";
$dsql->SetQuery($query);
$dsql->Execute("a");
while($row = $dsql->GetArray("a")){
$row['info'] = $row['infos'] = cn_substr($row['description'],$infolen);
$row['id'] = $row['id'];
if($row['corank'] > 0 && $row['arcrank']==0)
{
$row['arcrank'] = $row['corank'];
}
$row['filename'] = $row['arcurl'] = GetFileUrl($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']);
$row['typeurl'] = GetTypeUrl($row['typeid'],$row['typedir'],$row['isdefault'],$row['defaultname'],$row['ispart'],
$row['namerule2'],$row['moresite'],$row['siteurl'],$row['sitepath']);
if($row['litpic'] == '-' || $row['litpic'] == '')
{
$row['litpic'] = $GLOBALS['cfg_cmspath'].'/images/defaultpic.gif';
}
if(!preg_match("#^http:\/\/#i", $row['litpic']) && $GLOBALS['cfg_multi_site'] == 'Y')
{
$row['litpic'] = $GLOBALS['cfg_mainsite'].$row['litpic'];
}
$row['picname'] = $row['litpic'];
$row['stime'] = GetDateMK($row['pubdate']);
$row['typelink'] = "<a href='".$row['typeurl']."'>".$row['typename']."</a>";
$row['image'] = "<img src='".$row['picname']."' border='0' width='$imgwidth' height='$imgheight' alt='".preg_replace("#['><]#", "", $row['title'])."'>";
$row['imglink'] = "<a href='".$row['filename']."'>".$row['image']."</a>";
$row['fulltitle'] = $row['title'];
$row['title'] = cn_substr($row['title'], $titlelen);
if($row['color']!='') $row['title'] = "<font color='".$row['color']."'>".$row['title']."</font>";
if(preg_match('#b#', $row['flag'])) $row['title'] = "<strong>".$row['title']."</strong>";
//$row['title'] = "<b>".$row['title']."</b>";
$row['textlink'] = "<a href='".$row['filename']."'>".$row['title']."</a>";
$row['plusurl'] = $row['phpurl'] = $GLOBALS['cfg_phpurl'];
$row['memberurl'] = $GLOBALS['cfg_memberurl'];
$row['templeturl'] = $GLOBALS['cfg_templeturl'];
foreach($tcp->CTags as $k=>$v){
$tcp->Assign($k,$row[$v->GetName()]);
}
$str.=$tcp->GetResult();
}
return $str;
}
2:dedecms模板调用。
{dede:newcomment limit="4" titlelen="10"}
<li><a href="[field:arcurl/]">[field:title/]</a>
<p>[field:description function='cn_substr(@me,80)'/]...</p>
</li>
{/dede:newcomment}
这样我们就很简单的完成了dedecms调用最新评论的文章。
来源:http://www.chinab4c.com
来源于上海汽车租赁
最近更新
常用插件
- ecshop 匿名下单自动注册会
ecshop 匿名下单自动注册会员...
- ecsho成本利润统计分析插件
最近在二次开发ecshop过程中,很多朋友要求一款分析 ecshop成本和利润插...
- ecshop二次开发首页显示购
ecshop二次开发首页显示购买记录插件,用图文的方式,来处理在首页显示...
- ecshop二次开发直接优惠现
ecshop二次开发促销售功能插件,主要是扩展了ecshop促销功能,增加了更...
- ecshop打印快递发货单
ecshop打印快递发货单,这个问题是很常见的问题。在发货完成之后,有些...