Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's a pagination class I use:</p> <pre><code>&lt;?php class sitePagination{ public $currentPage; public $perPage; public $totalRecords; public function __construct($page = 1,$per_page = 2, $total_records = 0){ $this-&gt;currentPage = (int)$page; $this-&gt;perPage = (int)$per_page; $this-&gt;totalRecords = (int)$total_records; } public function totalPages(){ return ceil($this-&gt;totalRecords / $this-&gt;perPage); } public function previousPage(){ return $this-&gt;currentPage - 1; } public function nextPage(){ return $this-&gt;currentPage + 1; } public function previousPageExists(){ return $this-&gt;previousPage() &gt;= 1 ? true : false; } public function nextPageExists(){ return $this-&gt;nextPage() &lt;= $this-&gt;totalPages() ? true : false; } public function offset(){ return ($this-&gt;currentPage - 1) * $this-&gt;perPage; } } ?&gt; </code></pre> <p>And then in the page.html, I used this:</p> <pre><code>//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-&gt;blogs WHERE site_id = $wpdb-&gt;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-&gt;prepare("SELECT blog_id, domain, path FROM $wpdb-&gt;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-&gt;offset()}", $wpdb-&gt;siteid ); //echo "query is $query&lt;br/&gt;"; $terms = $wpdb-&gt;get_results($query,ARRAY_A); echo "&lt;ul&gt;"; foreach($terms as $detail) { //$cat_parent = get_category($detail-&gt;parent); //Had to use the $cat_parent to build the link //if some has a better idea, would be nice echo "&lt;li style='font-size:1.3em;'&gt;&lt;a href='http://".$detail[ 'domain' ].$detail['path']."'&gt;".get_blog_option( $detail['blog_id'], 'blogname' )."&lt;/a&gt;&lt;/li&gt;"; } // 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 "&lt;/ul&gt;"; //echo "&lt;span class='pages'&gt;Page {$page} of {$paginate-&gt;totalPages()}&lt;/span&gt;"; if($paginate-&gt;totalPages() &gt; 1){ if($paginate-&gt;previousPageExists()){ echo '&lt;a href="?cat='.$cat_parent-&gt;term_id.'&amp;current_page='.$paginate-&gt;previousPage().'"&gt;&amp;laquo; Previous&lt;/a&gt;'; } } if(ceil($paginate-&gt;totalPages()) &gt; 1){ for($i=1;$i &lt; ceil($paginate-&gt;totalPages()) + 1;$i++){ if($page == $i) echo '&lt;span class="current"&gt; '.$i.' &lt;/span&gt;'; else echo '&lt;a href="'.$cat_parent-&gt;slug.'/?current_page='.$i.'"&gt; '.$i.' &lt;/a&gt;'; } } if($paginate-&gt;totalPages() &gt; 1){ if($paginate-&gt;nextPageExists()){ echo '&lt;a href="?cat='.$cat_parent-&gt;term_id.'&amp;current_page='.$paginate-&gt;nextPage().'"&gt;Next &amp;raquo;&lt;/a&gt;'; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload