PHPCMS调用默认表最新文章有一下两种方法:
1. get标签形式调用
2. 修改标签代码实现最新文章调用
下面我们看看具体是实现方法:
第一种方法:用GET标签调用
这种方法不用修改PHPCMS的核心代码,就可以达到模型表的最新数据调用,具体代码片段如下:
{pc:get sql="SELECT * from v9_news where status=99 and catid in(21,22,23,24,25) order by id DESC" start=="7" num="7" return="data"}
{loop $data $r}
<li><a href="{$r[url]}" title="{$r[title]}" target="_blank">{str_cut($r['title'],40)}({date('m-d',$r[inputtime])})</span></a></li>
{/loop}
{/pc}
第二种方法:修改标签代码
PHPCMS的标签默认只能调用单个主栏目下面的子栏目的文章,如果不填写栏目则无法调用数据,填写多个栏目ID只调取首个栏目ID的文章,为什么这么说呢?看看代码就知道原因所在了.
/**
* 列表页标签
* @param $data
*/
public function lists($data) {
$catid = intval($data['catid']);
if(!$this->set_modelid($catid)) return false;
if(isset($data['where'])) {
$sql = $data['where'];
} else {
$thumb = intval($data['thumb']) ? " AND thumb != ''" : '';
if($this->category[$catid]['child']) {
$catids_str = $this->category[$catid]['arrchildid'];
$pos = strpos($catids_str,',')+1;
$catids_str = substr($catids_str, $pos);
$sql = "status=99 AND catid IN ($catids_str)".$thumb;
} else {
$sql = "status=99 AND catid='$catid'".$thumb;
/**
* 列表页标签
* @param $data
*/
public function lists($data) {
$catid = $data['catid'];
$cid = intval( <span style="font-family: Arial, Helvetica, sans-serif; font-size: 12px;">$catid </span>);
if(!$this->set_modelid($cid)) return false;
if(isset($data['where'])) {
$sql = $data['where'];
} else {
$thumb = intval($data['thumb']) ? " AND thumb != ''" : '';
if($cat_array=explode(',',$catid) ){
$catids_str = $catid;
foreach($cat_array as $k => $v){
if($this->category[$v]['child']) {
$catids_str .= ','.$this->category[$v]['arrchildid'];
}
}
$sql = "status=99 AND catid IN ($catids_str)".$thumb;
}else {
$sql = "status=99 AND catid='$catid'".$thumb;
}
}
$order = $data['order'];
$return = $this->db->select($sql, '*', $data['limit'], $order, '', 'id');
//调用副表的数据
if (isset($data['moreinfo']) && intval($data['moreinfo']) == 1) {
$ids = array();
foreach ($return as $v) {
if (isset($v['id']) && !emptyempty($v['id'])) {
$ids[] = $v['id'];
} else {
continue;
}
}
if (!emptyempty($ids)) {
$this->db->table_name = $this->db->table_name.'_data';
$ids = implode('/',/'', $ids);
$r = $this->db->select("`id` IN ('$ids')", '*', '', '', '', 'id');
if (!emptyempty($r)) {
foreach ($r as $k=>$v) {
if (isset($return[$k])) $return[$k] = array_merge($v, $return[$k]);
}
}
}
}
return $return;
}
大型站长资讯类网站! https://www.nzzz.com.cn