ѡ̳

标题: 新增获取栏目内容函数get_catcontent [打印本页]

作者: admin    时间: 2017-12-23 10:13
标题: 新增获取栏目内容函数get_catcontent
get_catcontent($r2['catid'],6)

  1. /**
  2. * 获取内容地址
  3. * @param $catid   栏目ID
  4. * @param $num     数量
  5. * @param $moreinfo  是否调用附表
  6. */
  7. function get_catcontent($catid=0,$num=10, $moreinfo = 0) {
  8.         static $category;
  9.         if(empty($category)) {
  10.                 $siteids = getcache('category_content','commons');
  11.                 $siteid = $siteids[$catid];
  12.                 $category = getcache('category_content_'.$siteid,'commons');
  13.         }
  14.   if(!isset($category[$catid])) return '';
  15.         $modelid = $category[$catid]['modelid'];
  16.         if(!$modelid) return '';
  17.         $db = pc_base::load_model('content_model');
  18.         $db->set_model($modelid);
  19.         //$r = $db->select(array('id'=>$id), '`url`');
  20.         $return = $db->select("status=99 AND catid='$catid'", '*', $num, 'listorder desc,id desc', '', 'id');
  21.          //print_r($return);
  22.         //获取附属表
  23.         //调用副表的数据
  24.          if ($moreinfo== 1) {
  25.                         $ids = array();
  26.                         foreach ($return as $v) {
  27.                                 if (isset($v['id']) && !empty($v['id'])) {
  28.                                         $ids[] = $v['id'];
  29.                                 } else {
  30.                                         continue;
  31.                                 }
  32.                         }
  33.                         if (!empty($ids)) {
  34.                                 $db->table_name = $db->table_name.'_data';
  35.                                 $ids = implode('\',\'', $ids);
  36.                                 $r = $db->select("`id` IN ('$ids')", '*', '', '', '', 'id');
  37.                                 if (!empty($r)) {
  38.                                         foreach ($r as $k=>$v) {
  39.                                                 if (isset($return[$k])) $return[$k] = array_merge($v, $return[$k]);
  40.                                         }
  41.                                 }
  42.                         }
  43.                 }
  44.                  

  45.         return $return;
  46. }
复制代码







欢迎光临 ѡ̳ (http://www.sunminxuan.cn/bbs/) Powered by Discuz! X3.4