Lo que quiero es que solo se muestren tres botones de pagina a cada lado de la pagina actual en la que se esta, y no muestre todos los botones de todas las paginas, el codigo es este:
Código PHP:
<?php
/*
Place code to connect to your DB here.
*/
$tbl_name="softwares"; //your table name
// How many adjacent pages should be shown on each side?
$adjacents = 3;
/*
First get total number of rows in data table.
If you have a WHERE clause in your query, make sure you mirror it here.
*/
$query = "SELECT COUNT(*) as num FROM $tbl_name WHERE catid=$bid";
$total_pages = mysql_fetch_array(mysql_query($query));
$total_pages = $total_pages['num'];
/* Setup vars for query. */
$targetpage = "browse.php"; //your file name (the name of this file)
$limit = 22; //how many items to show per page
if($page)
$start = ($page - 1) * $limit; //first item to display on this page
else
header('location:index.php'); //if no page var is given, set start to 1
/* Get data. */
$sql = "SELECT * FROM $tbl_name WHERE catid=$bid ORDER BY title LIMIT $start, $limit";
$result = mysql_query($sql);
/* Setup page vars for display. */
if ($page == 0) $page = 1; //if no page var is given, default to 1.
$prev = $page - 1; //previous page is page - 1
$next = $page + 1; //next page is page + 1
$lastpage = ceil($total_pages/$limit); //lastpage is = total pages / items per page, rounded up.
$lpm1 = $lastpage - 1; //last page minus 1
/*
Now we apply our rules and draw the pagination object.
We're actually saving the code to a variable in case we want to draw it more than once.
*/
$queryseo="SELECT * FROM seourls WHERE id = 1";
$resultseo=mysql_query($queryseo);
while ($row=mysql_fetch_array($resultseo)) {
# code...
$seourls=$row['status'];
}
if($seourls==0){
$pagination = "";
if($lastpage > 1)
{
$pagination .= "<div class=\"button-group\">";
//previous button
if ($page > 1)
$pagination.= "<a class=\"button green fastbutton\" href=\"$targetpage?page=$prev&bid=$bid&cat=$cat\">Página anterior</a>";
else
$pagination.= "<span class=\" button green button-dark fastbutton\">Página anterior</span>";
//pages
if ($lastpage < 7 + ($adjacents * 2)) //not enough pages to bother breaking it up
{
for ($counter = 1; $counter <= $lastpage; $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"button fastbutton blue current\">$counter</span>";
else
$pagination.= "<a class=\"button green fastbutton\" href=\"$targetpage?page=$counter&bid=$bid&cat=$cat\">$counter</a>";
}
}
elseif($lastpage > 5 + ($adjacents * 2)) //enough pages to hide some
{
//close to beginning; only hide later pages
if($page < 1 + ($adjacents * 2))
{
for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"button green \">$counter</span>";
else
$pagination.= "<a class=\"button green\" href=\"$targetpage?page=$counter&bid=$bid&cat=$cat\">$counter</a>";
}
$pagination.= "...";
$pagination.= "<a class=\"button green fastbutton\" href=\"$targetpage?page=$lpm1&bid=$bid&cat=$cat\">$lpm1</a>";
$pagination.= "<a class=\"button green fastbutton\" href=\"$targetpage?page=$lastpage&bid=$bid&cat=$cat\">$lastpage</a>";
}
//in middle; hide some front and some back
elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
{
$pagination.= "<a class=\"button green fastbutton\" href=\"$targetpage?page=1&bid=$bid&cat=$cat\">1</a>";
$pagination.= "<a class=\"button green fastbutton\" href=\"$targetpage?page=2&bid=$bid&cat=$cat\">2</a>";
$pagination.= "...";
for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"button fastbutton blue current\">$counter</span>";
else
$pagination.= "<a class=\"button fastbutton\" href=\"$targetpage?page=$counter&bid=$bid&cat=$cat\">$counter</a>";
}
$pagination.= "...";
$pagination.= "<a class=\"button green fastbutton\" href=\"$targetpage?page=$lpm1&bid=$bid&cat=$cat\">$lpm1</a>";
$pagination.= "<a class=\"button green fastbutton\" href=\"$targetpage?page=$lastpage&bid=$bid&cat=$cat\">$lastpage</a>";
}
//close to end; only hide early pages
else
{
$pagination.= "<a class=\"button green fastbutton\" href=\"$targetpage?page=1&bid=$bid&cat=$cat\">1</a>";
$pagination.= "<a class=\"button green fastbutton\" href=\"$targetpage?page=2&bid=$bid&cat=$cat\">2</a>";
$pagination.= "...";
for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"button fastbutton blue current\">$counter</span>";
else
$pagination.= "<a class=\"button green fastbutton\" href=\"$targetpage?page=$counter&bid=$bid&cat=$cat\">$counter</a>";
}
}
}
//next button
if ($page < $counter - 1)
$pagination.= "<a class=\"button green\" href=\"$targetpage?page=$next&bid=$bid&cat=$cat\">Página siguiente</a>";
else
$pagination.= "<span class=\"button green\">Página siguiente</span>";
$pagination.= "</div>\n";
}
}else{// seo urls////////////////////////////////////////////////////////////////////////////////////////
function create_slug($string){
$cat=preg_replace('/[^A-Za-z0-9-]+/', '-', $string);
return $cat;
}
$cat=create_slug($cat);
$pagination = "";
if($lastpage > 1)
{
$pagination .= "<div class=\"button-group\">";
//previous button
if ($page > 1)
$pagination.= "<a class=\"button green fastbutton\" href=\"$baseUrl/$prev/$bid/$cat\">Página anterior</a>";
else
$pagination.= "<span class=\" button green button-dark fastbutton\">Página anterior</span>";
//pages
if ($lastpage < 7 + ($adjacents * 2)) //not enough pages to bother breaking it up
{
for ($counter = 1; $counter <= $lastpage; $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"button fastbutton blue current\">$counter</span>";
else
$pagination.= "<a class=\"button green fastbutton\" href=\"$baseUrl/$counter/$bid/$cat\">$counter</a>";
}
}
elseif($lastpage > 5 + ($adjacents * 2)) //enough pages to hide some
{
//close to beginning; only hide later pages
if($page < 1 + ($adjacents * 2))
{
for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"button green \">$counter</span>";
else
$pagination.= "<a class=\"button green\" href=\"$baseUrl/$counter/$bid/$cat\">$counter</a>";
}
$pagination.= "...";
$pagination.= "<a class=\"button green fastbutton\" href=\"$baseUrl/$lpm1/$bid/$cat\">$lpm1</a>";
$pagination.= "<a class=\"button green fastbutton\" href=\"$baseUrl/$lastpage/$bid/$cat\">$lastpage</a>";
}
//in middle; hide some front and some back
elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
{
$pagination.= "<a class=\"button green fastbutton\" href=\"$baseUrl/1/$bid/$cat\">1</a>";
$pagination.= "<a class=\"button green fastbutton\" href=\"$baseUrl/2/$bid/$cat\">2</a>";
$pagination.= "...";
for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"button fastbutton blue current\">$counter</span>";
else
$pagination.= "<a class=\"button fastbutton\" href=\"$baseUrl/$counter/$bid/$cat\">$counter</a>";
}
$pagination.= "...";
$pagination.= "<a class=\"button green fastbutton\" href=\"$baseUrl/$lpm1/$bid/$cat\">$lpm1</a>";
$pagination.= "<a class=\"button green fastbutton\" href=\"$baseUrl/$lastpage/$bid/$cat\">$lastpage</a>";
}
//close to end; only hide early pages
else
{
$pagination.= "<a class=\"button green fastbutton\" href=\"$baseUrl/1/$bid/$cat\">1</a>";
$pagination.= "<a class=\"button green fastbutton\" href=\"$baseUrl/2/$bid/$cat\">2</a>";
$pagination.= "...";
for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"button fastbutton blue current\">$counter</span>";
else
$pagination.= "<a class=\"button green fastbutton\" href=\"$baseUrl/$counter/$bid/$cat\">$counter</a>";
}
}
}
//next button
if ($page < $counter - 1)
$pagination.= "<a class=\"button green\" href=\"$baseUrl/$next/$bid/$cat\">Página siguiente</a>";
else
$pagination.= "<span class=\"button green\">Página siguiente</span>";
$pagination.= "</div>\n";
}
}
?>