当前位置:首页 > CMS教程 > phpcms > 列表

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

发布:smiling 来源: PHP粉丝网  添加日期:2014-10-19 17:44:34 浏览: 评论:0 

调用栏目下最新文章,很简单,action="postion"改为"lists",一定要加上catid(栏目id),代码如下:

  1. {pc:content action="lists" catid="72" num="8" order="id DESC"} 
  2. <UL class=rt> 
  3. {loop $data $r} 
  4.   <li><a href="{$r[url]}" target="_blank">{str_cut($r[title],36,'')}</a></li> 
  5. {/loop} 
  6. </UL> 
  7. {/pc} 

Phpcms v9默认不支持调用全站最新文章,需要修改文件:\phpcms\modules\content\classes\content_tag.class.php,找到以下函数:

  1. public function lists($data) { 
  2. $catid = intval($data['catid']); 
  3. if(!$this->set_modelid($catid)) return false; 
  4. if(isset($data['where'])) { 
  5. $sql = $data['where']; 
  6. } else { 
  7. $thumb = intval($data['thumb']) ? " AND thumb != ''" : ''; 
  8. if($this->category[$catid]['child']) { 
  9. $catids_str = $this->category[$catid]['arrchildid']; 
  10. $pos = strpos($catids_str,',')+1; 
  11. $catids_str = substr($catids_str, $pos); 
  12. $sql = "status=99 AND catid IN ($catids_str)".$thumb; 
  13. } else { 
  14. $sql = "status=99 AND catid='$catid'".$thumb; 
  15. } 
  16. } 
  17. $order = $data['order']; 
  18. $return = $this->db->select($sql, '*', $data['limit'], $order, '', 'id'); 
  19. //调用副表的数据 
  20. if (isset($data['moreinfo']) && intval($data['moreinfo']) == 1) { 
  21. $ids = array(); 
  22. foreach ($return as $v) { 
  23. if (isset($v['id']) && !emptyempty($v['id'])) { 
  24. $ids[] = $v['id']; 
  25. } else { 
  26. continue; 
  27. } 
  28. } 
  29. if (!emptyempty($ids)) { 
  30. $this->db->table_name = $this->db->table_name.'_data'; 
  31. $ids = implode('\',\'', $ids); 
  32. $r = $this->db->select("`id` IN ('$ids')", '*', '', '', '', 'id'); 
  33. if (!emptyempty($r)) {  //phpfensi.com 
  34. foreach ($r as $k=>$v) { 
  35. if (isset($return[$k])) $return[$k] = array_merge($v, $return[$k]); 
  36. } 
  37. } 
  38. } 
  39. } 
  40. return $return; 
  41. } 

修改为:

  1. public function lists($data) { 
  2. $catid = intval($data['catid']); 
  3. if(isset($data['where'])) { 
  4. $sql = $data['where']; 
  5. } else { 
  6. $thumb = intval($data['thumb']) ? " AND thumb != ''" : ''; 
  7. if(!emptyempty($catid)) { 
  8. if(!$this->set_modelid($catid)) return false; 
  9. if($this->category[$catid]['child']) { 
  10. $catids_str = $this->category[$catid]['arrchildid']; 
  11. $pos = strpos($catids_str,',')+1; 
  12. $catids_str = substr($catids_str, $pos); 
  13. $sql = "status=99 AND catid IN ($catids_str)".$thumb; 
  14. } else { 
  15. $sql = "status=99 AND catid='$catid'".$thumb; 
  16. } 
  17. } 
  18. else { 
  19. $sql = "status=99".$thumb; 
  20. } 
  21. } 
  22. $order = $data['order']; 
  23. $return = $this->db->select($sql, '*', $data['limit'], $order, '', 'id'); 
  24. //调用副表的数据 
  25. if (isset($data['moreinfo']) && intval($data['moreinfo']) == 1) { 
  26. $ids = array(); 
  27. foreach ($return as $v) { 
  28. if (isset($v['id']) && !emptyempty($v['id'])) { 
  29. $ids[] = $v['id']; 
  30. } else { 
  31. continue; 
  32. } 
  33. } 
  34. if (!emptyempty($ids)) { 
  35. $this->db->table_name = $this->db->table_name.'_data'; 
  36. $ids = implode('\',\'', $ids); 
  37. $r = $this->db->select("`id` IN ('$ids')", '*', '', '', '', 'id'); 
  38. if (!emptyempty($r)) { 
  39. foreach ($r as $k=>$v) { 
  40. if (isset($return[$k])) $return[$k] = array_merge($v, $return[$k]); 
  41. } 
  42. } 
  43. } 
  44. } 
  45. return $return; 
  46. } 

调用方法:{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"毫秒

Tags: phpcms最新文章 phpcms调用文章

分享到: