같은 것을 얻을 wan't는 매김 내가 사용하는 클래스의 다음 page.html에서 다음
<?php
class sitePagination{
public $currentPage;
public $perPage;
public $totalRecords;
public function __construct($page = 1,$per_page = 2, $total_records = 0){
$this->currentPage = (int)$page;
$this->perPage = (int)$per_page;
$this->totalRecords = (int)$total_records;
}
public function totalPages(){
return ceil($this->totalRecords/$this->perPage);
}
public function previousPage(){
return $this->currentPage - 1;
}
public function nextPage(){
return $this->currentPage + 1;
}
public function previousPageExists(){
return $this->previousPage() >= 1 ? true : false;
}
public function nextPageExists(){
return $this->nextPage() <= $this->totalPages() ? true : false;
}
public function offset(){
return ($this->currentPage - 1) * $this->perPage;
}
}
?>
그리고, 나는 이것을 사용 :
//include the paginate class. I put it in the theme folder
include("paginate.php");
//This is the SQL Query to get the number of rows I have
$count = "SELECT COUNT(*) FROM $wpdb->blogs WHERE site_id = $wpdb->siteid AND public = '1' AND archived = '0' AND mature = '0' AND spam = '0' AND deleted = '0' AND last_updated != '0000-00-00 00:00:00'";
$number = mysql_query($count);
$row = mysql_fetch_array($number);
$num_rows = array_shift($row);
//Define some variable to hold our pagination settings
$page = !empty($_GET['current_page']) ? (int)$_GET['current_page'] : 1;
$perPage = 5;
$paginate = new sitePagination($page,$perPage,$num_rows);
//This is the actual SQL Query to fetch the Data from Database
$query = $wpdb->prepare("SELECT blog_id, domain, path FROM $wpdb->blogs WHERE site_id = %d AND public = '1' AND archived = '0' AND mature = '0' AND spam = '0' AND deleted = '0' AND last_updated != '0000-00-00 00:00:00' ORDER BY last_updated DESC LIMIT {$perPage} OFFSET {$paginate->offset()}", $wpdb->siteid);
//echo "query is $query<br/>";
$terms = $wpdb->get_results($query,ARRAY_A);
echo "<ul>";
foreach($terms as $detail)
{
//$cat_parent = get_category($detail->parent);
//Had to use the $cat_parent to build the link
//if some has a better idea, would be nice
echo "<li style='font-size:1.3em;'><a href='http://".$detail[ 'domain' ].$detail['path']."'>".get_blog_option($detail['blog_id'], 'blogname')."</a></li>";
}
// The Fun starts here, all the code below will generate our dynamic page number
// The container class is the same as WP PAGENAVI
// I'm using a custom pagination class I created
echo "</ul>";
//echo "<span class='pages'>Page {$page} of {$paginate->totalPages()}</span>";
if($paginate->totalPages() > 1){
if($paginate->previousPageExists()){
echo '<a href="?cat='.$cat_parent->term_id.'¤t_page='.$paginate->previousPage().'">« Previous</a>';
}
}
if(ceil($paginate->totalPages()) > 1){
for($i=1;$i < ceil($paginate->totalPages()) + 1;$i++){
if($page == $i)
echo '<span class="current"> '.$i.' </span>';
else
echo '<a href="'.$cat_parent->slug.'/?current_page='.$i.'"> '.$i.' </a>';
}
}
if($paginate->totalPages() > 1){
if($paginate->nextPageExists()){
echo '<a href="?cat='.$cat_parent->term_id.'¤t_page='.$paginate->nextPage().'">Next »</a>';
}
}
이 오류가 발생합니다. 경고 : mysql_fetch_array()는 13 번 줄에있는 C : \ xampp \ htdocs \ wordpress \ wp-content \ themes \ safwan \ page-paginated.php에 주어진 매개 변수 1을 리소스로 사용합니다. Warning : array_shift 1 배열, C : \ xampp \ htdocs \ wordpress \ wp-content \ themes \ safwan \ page-paginated.php 14 줄에 NULL로 주어진 – esafwan
줄 13 : $ row = mysql_fetch_array ($ number); 그리고 Line 14는 $ num_rows = array_shift ($ row); – esafwan
$ wpdb-> blogs와 $ wpdb-> siteid 변수가 실제로 채워 졌는지 확인해야합니다. 나는 이것을 위해 3.0을 사용하고 있었다. 이 vars가 예상 한 것을 반향 출력하지 않으면 $ count 변수를 채우는 쿼리의 결과를 버리게됩니다. –