dedecms通过栏目关键字调用文章
2013-02-21 00:45 来源:www.chinab4c.com 作者:dedecms专家
dedecms通过栏目关键字调用文章,就是通过dedecms的栏目设置的关键字,以及对该栏目下文章标题进行匹配,如果该文章标题含有该分类下面的关键字,就调用出来。
1:dedecms模板调用
{dede:typekeys limit="3" titlelen="10"}
<a href="[field:arcurl/]">[field:title/]<br></a>
{/dede:typekeys}
2:dedecms标签函数
function lib_typekeys(&$ctag,&$refObj)
{
global $dsql,$envs,$cfg_cmsurl;
$keywords = $refObj->Fields['keywords'];
$val = explode(",",$keywords);
if(empty($val)) return '';
$tmp = '';
foreach($val as $k){
$tmp.=empty($tmp)? '':'or' ;
$tmp.=" arc.title like '%".$k."%'";
}
if($tmp){
$tmp =" and ($tmp)";
}
$list = "limit|5";
FillAttsDefault($ctag->CAttribute->Items,$list);
extract($ctag->CAttribute->Items);
$tcp = new DedeTagParse();
$tcp->SetNameSpace('field','[',']');
$tcp->LoadSource($ctag->GetInnerText());
$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 ";
$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 $tmp $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;
}
以上就实现了dedecms通过栏目关键字调用文章.
来源:http://www.chinab4c.com
最近更新
常用插件
- ecshop打印快递发货单
ecshop打印快递发货单,这个问题是很常见的问题。在发货完成之后,有些...
- ecsho成本利润统计分析插件
最近在二次开发ecshop过程中,很多朋友要求一款分析 ecshop成本和利润插...
- ecshop二次开发直接优惠现
ecshop二次开发促销售功能插件,主要是扩展了ecshop促销功能,增加了更...
- ecshop 匿名下单自动注册会
ecshop 匿名下单自动注册会员...
- ecshop二次开发首页显示购
ecshop二次开发首页显示购买记录插件,用图文的方式,来处理在首页显示...