Skip to content

Instantly share code, notes, and snippets.

@Ollo
Created January 25, 2015 17:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ollo/c5e445930c40ac709c72 to your computer and use it in GitHub Desktop.
Save Ollo/c5e445930c40ac709c72 to your computer and use it in GitHub Desktop.
wp pagination
// paging code
// Query to count rows.
$result = mysql_query("SELECT * FROM Table_Name WHERE Column_Name = '$section'")
$items = 32; // number of items per page.
$all = $_GET['a'];
$num_rows = mysql_num_rows($result);
if($all == "all"){
$items = $num_rows;
}
$nrpage_amount = $num_rows/$items;
$page_amount = ceil($num_rows/$items);
$page_amount = $page_amount-1;
$page = mysql_real_escape_string($_GET['p']);
if($page < "1"){
$page = "0";
}
$p_num = $items*$page;
//end paging code
// Query that you would like to SHOW
$result = mysql_query("SELECT * FROM Table_Name WHERE Column_Name = '$section' ORDER BY 'name' ASC LIMIT $p_num , $items");
function paging(){
Global $num_rows;
global $page;
global $page_amount;
global $section;
if($page_amount != "0"){
echo "<div class=paging>";
if($page != "0"){
$prev = $page-1;
echo "<a href=\"section.php?q=$section&p=$prev\">Prev</a>";
}
for ( $counter = 0; $counter <= $page_amount; $counter += 1) {
echo "<a href=\"section.php?q=$section&p=$counter\">";
echo $counter+1;
echo "</a>";
}
if($page < $page_amount){
$next = $page+1;
echo "<a href=\"section.php?q=$section&p=$next\">Next</a>";
}
echo "<a href=\"section.php?q=$section&a=all\">View All</a>";
echo "</div>";
}
} // close paging function
// call on Pagination with function
paging();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment