织梦在栏目页根据栏目关键字调用相关文章(可指定调用哪个栏目)
2020-04-08
{dede:field.keywords runphp=yes} global $dsql,$aid,$id; $aid = $aid ? $aid : $id; $keyword = ''; if(!empty(@me)) { $keywords = explode(',' , trim(@me)); $keyword = ''; $n = 1; foreach($keywords as $k) { if($n > 3) break; if(trim($k)=='') continue; else $k = addslashes($k); $keyword .= ($keyword=='' ? " CONCAT(arc.keywords,' ',arc.title) LIKE '%$k%' " : " OR CONCAT(arc.keywords,' ',arc.title) LIKE '%$k%' "); $n++; } } if($keyword != '') { $sql = "SELECT arc.*,tp.typedir,tp.typename,tp.corank,tp.isdefault,tp.defaultname,tp.namerule,tp.namerule2,tp.ispart,tp.moresite,tp.siteurl,tp.sitepath FROM `#@__archives` arc LEFT JOIN `#@__arctype` tp ON arc.typeid=tp.id where arc.arcrank>-1 AND ($keyword) AND arc.id<>'$aid' AND typeid in(1,2,3,4) ORDER BY arc.id desc limit 0, 10"; } $dsql->SetQuery($sql); $dsql->Execute('t'); $result = ''; while($row = $dsql->GetArray('t')) { $arcurl = GetOneArchive($row['id']); $row['pubdate'] = MyDate('Y-m-d',$row['pubdate']); $result .= <<< TPL <ul class="d4"> <li> <a href="{$arcurl['arcurl']}"><img src="{$row['litpic']}" alt="{$row['title']}"></a> <a href="{$arcurl['arcurl']}">{$row['title']}</a> <p>作者:{$row['writer']}</p> <p>时间:{$row['pubdate']}</p> <p>来源:{$row['source']}</p> <p>描述:{$row['description']}</p> </li> </ul> TPL; } @me = $result; {/dede:field.keywords} // AND typeid in(1,2,3,4) 指定栏目 // limit 0, 10 输入文章条数