Scripts
Paginanummering
Veel mensen vroegen allemaal script voor het nummeren van pagina's. Vandaar deze script. het is niet allemaal van mij, maar weet de bron niet meer. To do: de variabele aanpassen in de script.
paginanummering
[code]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Paginanummering</title>
<style type="text/css">
body{font-family:Arial, Helvetica, sans-serif; font-size:12px;}
h2{clear:both; border:0; margin:0; padding-top:30px; font-size:13px;}
p{border:0; margin:0; padding:0; padding-bottom:20px;}
</style>
<style type="text/css">
/* -------------------------------------------- */
/* Pagination: Digg Style */
/* -------------------------------------------- */
ul{border:0; margin:0; padding:0;}
#pagination-digg li{
border:0; margin:0; padding:0;
font-size:11px;
list-style:none;
}
#pagination-digg a{
border:solid 1px #9aafe5;
margin-right:2px;
}
#pagination-digg .previous-off,
#pagination-digg .next-off {
border:solid 1px #DEDEDE;
color:#888888;
display:block;
float:left;
font-weight:bold;
margin-right:2px;
padding:3px 4px;
}
#pagination-digg .next a,
#pagination-digg .previous a {
font-weight:bold;
}
#pagination-digg .active{
background:#2e6ab1;
color:#FFFFFF;
font-weight:bold;
display:block;
float:left;
padding:4px 6px;
}
#pagination-digg a:link,
#pagination-digg a:visited {
color:#0e509e;
display:block;
float:left;
padding:3px 6px;
text-decoration:none;
}
#pagination-digg a:hover{
border:solid 1px #0e509e;
}
</style>
</head>
<body>
<?php
////////////////////////////////////////////
/// Edit by: Daniël ///
/// xfire: tjonger ///
////////////////////////////////////////////
$host = ""; // De host van uw server. 99 van de 100 keer is dit localhost.
$user = ""; // De gebruiker van de database. Bij het aanmaken van de database heeft u dit moeten opgeven.
$pass = ""; // Het wachtwoord van de database. Bij het aanmaken van de database heeft u dit moeten opgeven.
$db = ""; // De database. Bij het aanmaken van de database heeft u dit moeten opgeven.
$table = "l"; // naam van je mysql table
$max = 10; // aantal items per pagina
///////////////////////////////////////////////////
// Niks aanpassen, als je niet weet wat je doet. //
///////////////////////////////////////////////////
$conn = mysql_connect($host,$user,$pass) or die(mysql_error());
$db = mysql_select_db($db);
// find out how many rows are in the table
$sql = "SELECT COUNT(*) FROM $table";
$result = mysql_query($sql, $conn);
$r = mysql_fetch_row($result);
$numrows = $r[0];
// find out total pages
$totalpages = ceil($numrows / $max);
// get the current page or set a default
if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
// cast var as int
$currentpage = (int) $_GET['currentpage'];
} else {
// default page num
$currentpage = 1;
} // end if
// if current page is greater than total pages...
if ($currentpage > $totalpages) {
// set current page to last page
$currentpage = $totalpages;
} // end if
// if current page is less than first page...
if ($currentpage < 1) {
// set current page to first page
$currentpage = 1;
} // end if
// the offset of the list, based on current page
$offset = ($currentpage - 1) * $rowsperpage;
/****** build the pagination links ******/
// range of num links to show
$range = 3;
echo "<ul id=\"pagination-digg\">";
// if not on page 1, don't show back links
if ($currentpage > 1) {
// get previous page num
echo " <li class=\"next\"><a href='{$_SERVER['PHP_SELF']}?currentpage=1'>«« Eerste pagina</a><li> ";
$prevpage = $currentpage - 1;
// show < link to go back to 1 page
echo " <li class=\"next\"><a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'>« Vorige</a><li> ";
} // end if
// loop to show links to range of pages around current page
for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
// if it's a valid page number...
if (($x > 0) && ($x <= $totalpages)) {
// if we're on current page...
if ($x == $currentpage) {
// 'highlight' it but don't make a link
echo " <li class=\"active\">$x</li> ";
// if not current page...
} else {
// make it a link
echo " <li><a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a><li> ";
} // end else
} // end if
} // end for
// if not on last page, show forward and last page links
if ($currentpage != $totalpages) {
// get next page
$nextpage = $currentpage + 1;
// echo forward link for next page
echo " <li class=\"next\"><a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>Volgende »</a></li> ";
echo " <li class=\"next\"><a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>Laatste pagina »»</a></li> ";
} // end if
/****** end build pagination links ******/
echo "</ul>";
?>
</body>
</html>
[/code]
Reacties
0