/** * [list 根据页码查询并处理文章数据] * @Author Rukic * @DateTime 2015-12-10T12:02:16+0800 * @return [type] [description] */ public function listData($now, $end) { $sql = "SELECT * FROM " . $this->table . " AS a," . C('DB_PREFIX') . $this->catetable . " AS cate," . C("DB_PREFIX") . $this->ctable . " AS col WHERE a.display=1 AND a.category_id=cate.cid AND a.column_id=col.id ORDER BY a.create_time desc LIMIT " . $now . "," . $end; // echo $sql;die; $article = $this->query($sql); // p($article);die; return article_data_ready($article); }
function arclist($attr, $content, &$smarty) { $model = 'article'; // p($attr);die; //获得指定文章 $aid = intval(isset($attr['aid']) ? $attr['aid'] : 0); //获得指定栏目文章 $cid = intval(isset($attr['cid']) ? $attr['cid'] : 0); //显示条数 $row = isset($attr['row']) ? $attr['row'] : 10; //标题长度 $titlelen = isset($attr['titlelen']) ? $attr['titlelen'] : '10'; //简介长度 $infolen = isset($attr['infolen']) ? intval($attr['infolen']) : 80; //是否只获取有缩略图的文章 1获得只有图片的 0 有没有都行 $image = intval(isset($attr['image']) ? $attr['image'] : 0); //排序 //显示类型 hot 热门文章 new 最新文章 $order = isset($attr['order']) ? strtolower(trim($attr['order'])) : ''; //对快进行命名 $bname = isset($attr['name']) ? $attr['name'] : "field"; // echo $image;die; /*==========================语句重组===============================*/ $adb = M($model); //实例化一个数据库模型 //---------------------------where------------------------------- if ($aid) { //指定文章id $adb->where("aid=" . $aid); } if ($cid) { $adb->where("column_id=" . $cid); } if ($image) { $adb->where("thumb <> ''"); } //---------------------------order------------------------------- if ($order) { switch ($order) { case 'hot': //查看次数最多 $order = 'hits DESC'; break; case 'rand': //随机排序 $order = 'rand()'; break; case 'new': //最新文章 $order = 'create_time DESC'; break; default: // \$order= str_replace(array('aid','cid'), array(\$db->table.'.aid','category.cid'), \$order); } } else { $order = 'aid DESC'; } //---------------------------查询条件------------------------------- //---------------------------limit------------------------------- $result = $adb->order($order)->limit($row)->all(); //---------------------------重组文章数据------------------------------- $article = array(); $str = ""; $result = article_data_ready($result); foreach ($result as $index => $field) { // $field=article_data_ready($field); $field['_index'] = $index; $field['_first'] = $index == 0 ? true : false; $field['_last'] = $index == count($result) - 1 ? true : false; $field['title'] = mb_substr($field['title'], 0, $titlelen, 'utf8'); $field['title'] = $field['highlight'] ? "<span style='color:red'>" . $field['title'] . "</span>" : $field['title']; $field['excerpt'] = mb_substr($field['excerpt'], 0, $infolen, 'utf-8'); /*if($field['new_window'] || $field['redirecturl']){ $field['link']='<a href="'.$field['url'].'" target="_blank">'.$field['title'].'</a>'; }else{ $field['link']='<a href="'.$field['url'].'">'.$field['title'].'</a>'; }*/ $article[] = $field; $fieldName = array_keys($field); $temp = $content; foreach ($fieldName as $name) { $temp = str_replace("[\$" . $bname . "." . $name . "]", $field[$name], $temp); } $str .= $temp; } $smarty->assign("list", $article); return $str; }