加入收藏 | 设为首页 | 会员中心 | 我要投稿 南平站长网 (https://www.0599zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 运营中心 > 建站资源 > 经验 > 正文

phpcms v9怎么调用网站最新文章

发布时间:2021-12-18 11:03:57 所属栏目:经验 来源:互联网
导读:调用栏目下最新文章,很简单,action=postion改为lists,一定要加上catid(栏目id),代码如下: {pc:content action=lists catid=72 num=8 order=id DESC} UL class=rt {loop $data $r} lia href={$r[url]} target=_blank{str_cut($r[title],36,)}/a/li {/loop}
调用栏目下最新文章,很简单,action="postion"改为"lists",一定要加上catid(栏目id),代码如下:
 
{pc:content action="lists" catid="72" num="8" order="id DESC"}
<UL class=rt>
{loop $data $r}
  <li><a href="{$r[url]}" target="_blank">{str_cut($r[title],36,'')}</a></li>
{/loop}
</UL>
{/pc}
Phpcms v9默认不支持调用全站最新文章,需要修改文件:/phpcms/modules/content/classes/content_tag.class.php,找到以下函数:
 
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;
}
}
$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)) {  //Cuoxin.com
foreach ($r as $k=>$v) {
if (isset($return[$k])) $return[$k] = array_merge($v, $return[$k]);
}
}
}
}
return $return;
}
修改为:
 
public function lists($data) {
$catid = intval($data['catid']);
if(isset($data['where'])) {
$sql = $data['where'];
} else {
$thumb = intval($data['thumb']) ? " AND thumb != ''" : '';
if(!emptyempty($catid)) {
if(!$this->set_modelid($catid)) return false;
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;
}
}
else {
$sql = "status=99".$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;
}
调用方法:{pc:content action="lists" num="10" order="id DESC" cache="3600"}
 
pc标签值:
 
action="lists"--------------内容数据(文章)列表
 
order="id DESC"---------------------排序类型="id DESC"
 
num="10" ----------------------数据调用数量="10"
 
cache="3600"-------------------缓存="3600"毫秒

(编辑:南平站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读