Phpcms V9 调用全站最新文章的代码

teaxia
2014-02-13 / 0 评论 / 72 阅读 / 正在检测是否收录...

调用栏目下最新文章,很简单,action="postion"改为"lists",一定要加上catid

{pc:content action="lists" catid="72" num="8" order="id DESC"}
<UL>
{loop $data $r}
<LI><a href="{$r[url]}" target="_blank">{str_cut($r[title],36,'')}</a></LI>
{/loop}
</UL>{/pc}

 

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

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

修改为:

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

修改代码后,即能调取全站最新文章。
调用方法:{pc:content action="lists" num="10" order="id DESC" cache="3600"}

0

评论 (0)

取消