/* TABLE = ff_posts post_status = publish post_date post_type = post ID TABLE = ff_term_relationships term_taxonomy_id = term id object_ID = ID 地方新聞 = term id = 2 最新消息 term id = 1 系統公告 term id = 9 */ include_once("./wp-config.php"); $type=intval($_GET["type"]); if ($type == 2) { $type = 2; $linkName = "local-news"; } else if ($type == 9) { $type = 9; $linkName = "announcement"; } else { $type = 1; $linkName = "news"; } $connection = @mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); mysqli_set_charset($connection, "utf8"); $extraLink = ""; $stDate = $_GET["stDate"]; $edDate = $_GET["edDate"]; if (!ckDateOnly($stDate)) {$stDate = "";} if (!ckDateOnly($edDate)) {$edDate = "";} if ($stDate != "" && $edDate != "") { $extraLink .= " AND post_date >= '$stDate' AND post_date <= '$edDate' "; } else if ($stDate != "") { $extraLink .= " AND post_date >= '$stDate' "; } else if ($edDate != "") { $extraLink .= " AND post_date <= '$edDate' "; } $searchQ = $_GET["searchQ"]; $searchQ = str_replace("'","",$searchQ); $searchQ = str_replace("\\","",$searchQ); $searchQ = str_replace('"',"",$searchQ); if ($searchQ != "") { $searchQT = mysqli_real_escape_string($connection,$searchQ); $extraLink .= " AND post_title like '%$searchQT%' "; } $sql = "SELECT count(*) as total FROM wp_posts AS a LEFT JOIN wp_term_relationships AS b ON a.ID = b.object_id WHERE b.term_taxonomy_id = '$type' AND a.post_status='publish' AND post_type='post' $extraLink "; $qy = mysqli_query($connection,$sql); $result = array(); if($qy){ while ($row = $qy->fetch_object()){ array_push($result,$row); } } $data_nums = $result[0]->total; mysqli_free_result($qy); $per = 10; $pages = ceil($data_nums/$per); if (!isset($_GET["page"])){ //假如$_GET["page"]未設置 $page=1; //則在此設定起始頁數 } else { $page = intval($_GET["page"]); //確認頁數只能夠是數值資料 } $start = ($page-1)*$per; $sql = "SELECT a.post_date,a.post_title,a.ID FROM wp_posts AS a LEFT JOIN wp_term_relationships AS b ON a.ID = b.object_id WHERE b.term_taxonomy_id = '$type' AND a.post_status='publish' AND post_type='post' $extraLink ORDER BY a.post_date DESC LIMIT $start,$per "; $qy = mysqli_query($connection, $sql); $result = array(); if($qy){ while ($row = $qy->fetch_object()){ array_push($result,$row); } } mysqli_free_result($qy); echo '
'.substr($result[$i]->post_date,0,10).' | '; echo ''.$result[$i]->post_title.' | '; echo ''; } echo '