public function pageCode() { $html = ''; $model = FrontData::getInstance(); $home = HomeController::getInstance(); $pache = $GLOBALS['pache']; $page = $home->page; if (isset($home->tag)) { $listingType = 'tag'; $listingTypeValue = $home->tag; } else { if (isset($home->categories)) { $listingType = 'categories'; $listingTypeValue = $home->categories; } else { $listingType = ''; $listingTypeValue = NULL; } } $countPage = ceil($model->articleCount($listingType, $listingTypeValue) / $pache->pagelimit); $i = $page; if ($i - 4 < 1) { $i = 5; } for ($i = $i - 4; $i < $page + 5; ++$i) { if ($i > $countPage) { break; } $url = '?'; if (isset($_GET[$listingType])) { $url .= $listingType . '=' . urlencode($_GET[$listingType]) . '&'; } if ($page == $i) { $html .= '<a class="pagecode current"><div class="code">' . $i . '</div><div class="bg"></div></a>'; } else { $html .= '<a class="pagecode" href="' . $url . 'page=' . $i . '">' . $i . '</a> '; } } $form = '<form method="get" style="display:none;"><input name="page" size="4" /></form>'; $html = '<div id="page">' . $html . $form . '</div>'; return $html; }
} $page = $this->page - 1; /* 以分类遍历 */ if (isset($_GET['categories'])) { $this->categories = $_GET['categories']; $this->listingType = 'categories'; } else { if (isset($_GET['tag'])) { $this->tag = explode(' ', trim($_GET['tag'])); $this->listingType = 'tag'; } else { $this->listingType = 'id'; } } } public function __construct() { $this->router(); $this->getArticles(); } private static $instance; public static function getInstance($params = array()) { if (!self::$instance instanceof self) { self::$instance = new self($params); } return self::$instance; } } $home = HomeController::getInstance(); require_once './front/home.php';