article.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. if (!defined('ES_PATH')) {
  3. exit('Access Denied');
  4. }
  5. class ArticleController extends Controller
  6. {
  7. public function index()
  8. {
  9. global $_W;
  10. global $_GPC;
  11. $pindex = max(1, intval($_GPC['page']));
  12. $psize = 10;
  13. $condition = ' and a.status = 1 ';
  14. $params = array();
  15. if (!empty($_GPC['keyword'])) {
  16. $_GPC['keyword'] = trim($_GPC['keyword']);
  17. $condition .= ' and a.title like :keyword';
  18. $params[':keyword'] = '%' . $_GPC['keyword'] . '%';
  19. }
  20. if (!empty($_GPC['cate'])) {
  21. $cateid = intval($_GPC['cate']);
  22. $condition .= ' and a.cate = :cate';
  23. $params[':cate'] = $cateid;
  24. }
  25. $articles = pdo_fetchall('SELECT a.* ,c.id as cid,c.name FROM ' . tablename('ewei_shop_system_article') . ' AS a
  26. LEFT JOIN ' . tablename('ewei_shop_system_category') . (' AS c ON a.cate = c.id and c.status = 1
  27. WHERE 1 ' . $condition . ' ORDER BY a.displayorder DESC LIMIT ') . ($pindex - 1) * $psize . ',' . $psize, $params);
  28. $total = pdo_fetchcolumn('SELECT count(1) FROM ' . tablename('ewei_shop_system_article') . ' as a WHERE 1 ' . $condition, $params);
  29. $category = pdo_fetchall('select id,name from ' . tablename('ewei_shop_system_category') . ' where status = 1 order by displayorder asc ');
  30. $pager = $this->pagination($total, $pindex, $psize);
  31. $basicset = $this->basicset();
  32. $title = '最新文章';
  33. include $this->template('article/index');
  34. }
  35. public function detail()
  36. {
  37. global $_W;
  38. global $_GPC;
  39. $id = intval($_GPC['id']);
  40. $article = pdo_fetch('SELECT * FROM ' . tablename('ewei_shop_system_article') . ' AS a
  41. LEFT JOIN ' . tablename('ewei_shop_system_category') . ' AS c ON a.cate = c.id
  42. WHERE a.id = ' . $id);
  43. $articles = pdo_fetchall('SELECT * FROM ' . tablename('ewei_shop_system_article') . ' AS a
  44. WHERE a.status = 1 ORDER BY RAND() DESC LIMIT 4 ');
  45. $relevant_top = pdo_fetch('SELECT * FROM ' . tablename('ewei_shop_system_article') . ' AS a
  46. WHERE a.status = 1 ORDER BY RAND()');
  47. $relevant = pdo_fetchall('SELECT * FROM ' . tablename('ewei_shop_system_article') . ' AS a
  48. WHERE a.status = 1 ORDER BY RAND() DESC LIMIT 6 ');
  49. $basicset = $this->basicset();
  50. $title = $article['title'];
  51. include $this->template('article/detail');
  52. }
  53. }
  54. ?>