page-news.php
<?PHP
/*--------------------------------------------------------------------------------------
@Desc : Simple and Cool Paging with PHP
@author : SachinKRaj - http://blog.sachinkraj.com
@updates : http://blog.sachinkraj.com/how-to-create-simple-paging-with-php-cs/
@Comments : If you like my work, please drop me a comment on the above post link.
Thanks!
---------------------------------------------------------------------------------------*/
function check_integer($which) {
if(isset($_REQUEST[$which])){
if (intval($_REQUEST[$which])>0) {
//check the paging variable was set or not,
//if yes then return its number:
//for example: ?page=5, then it will return 5 (integer)
return intval($_REQUEST[$which]);
} else {
return false;
}
}
return false;
}//end of check_integer()
function get_current_page() {
if(($var=check_integer('page'))) {
//return value of 'page', in support to above method
return $var;
} else {
//return 1, if it wasnt set before, page=1
return 1;
}
}//end of method get_current_page()
function doPages($page_size, $thepage, $query_string, $total=0) {
//per page count
$index_limit = 10;
//set the query string to blank, then later attach it with $query_string
$query='';
if(strlen($query_string)>0){
$query = "&".$query_string;
}
//get the current page number example: 3, 4 etc: see above method description
$current = get_current_page();
$total_pages=ceil($total/$page_size);
$start=max($current-intval($index_limit/2), 1);
$end=$start+$index_limit-1;
echo '<br /><br /><div class="paging">';
// Previous <<
if($current==1) {
echo '<span class="prn">< < </span> ';
} else {
$i = $current-1;
echo '<a href="'.$thepage.'?page='.$i.$query.'" class="prn" rel="nofollow" title="go to page '.$i.'">< < </a> ';
echo '<span class="prn">...</span> ';
}
if($start > 1) {
$i = 1;
echo '<a href="'.$thepage.'?page='.$i.$query.'" title="go to page '.$i.'">'.$i.'</a> ';
}
for ($i = $start; $i <= $end && $i <= $total_pages; $i++){
if($i==$current) {
echo '<span>'.$i.'</span> ';
} else {
echo '<a href="'.$thepage.'?page='.$i.$query.'" title="go to page '.$i.'">'.$i.'</a> ';
}
}
if($total_pages > $end){
$i = $total_pages;
echo '<a href="'.$thepage.'?page='.$i.$query.'" title="go to page '.$i.'">'.$i.'</a> ';
}
// Next >>
if($current < $total_pages) {
$i = $current+1;
echo '<span class="prn">...</span> ';
echo '<a href="'.$thepage.'?page='.$i.$query.'" class="prn" rel="nofollow" title="go to page '.$i.'"> > ></a> ';
// Next >>
} else {
echo '<span class="prn"> > ></span> ';
}
//if nothing passed to method or zero, then dont print result, else print the total count below:
if ($total != 0){
//prints the total result count just below the paging
echo '<p id="total_count">(total '.$total.' results)</p></div>';
}
}//end of method doPages()
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>How to create simple cool paging with PHP and CSS</title>
</head>
<style type="text/css">
/*---Lets style paging to make it look more cool--*/
/*--example specific styling: you dont need it really in your script, it is just to make this example look good---*/
body { font-family: Helvetica, arial, sans-serif; font-size:13px; font-weight: normal;}
/*---Paging specific styling----*/
.paging { padding:10px 0px 0px 0px; text-align:center; font-size:13px;}
.paging.display{text-align:right;}
.paging a, .paging span {padding:2px 8px 2px 8px; font-weight :normal}
.paging span {font-weight:bold; color:#000; font-size:13px; }
.paging a, .paging a:visited {color:#000; text-decoration:none; border:1px solid #dddddd;}
.paging a:hover { text-decoration:none; background-color:#6C6C6C; color:#fff; border-color:#000;}
.paging span.prn { font-size:13px; font-weight:normal; color:#aaa; }
.paging a.prn, .paging a.prn:visited { border:2px solid #dddddd;}
.paging a.prn:hover { border-color:#000;}
.paging p#total_count{color:#aaa; font-size:12px; font-weight: normal; padding-top:8px; padding-left:18px;}
.paging p#total_display{color:#aaa; font-size:12px; padding-top:10px;}
</style>
<?php get_header(); ?>
<div id="body">
<div id="content">
<div id="main">
<h4>LOREM IPSUM - <font color="red"><?php the_time('d'); ?> <?php the_time('M'); ?> <?php the_time('Y'); ?></font></h4>
<div class="post">
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<p style="border-bottom: 2px dotted #FF0000; width: 900px;"></p><br />
<img src="<?php echo get_stylesheet_directory_uri(); ?>/images/pic1.png" ALT="picture1" ALIGN=LEFT><div id="ptitle"><?php the_title(); ?><font color="black"> - <?php the_time('d'); ?> <?php the_time('M'); ?> <?php the_time('Y'); ?></font></div>
<p><?php the_content(''); ?>
<?PHP
//This is the actual usage of function, It prints the paging links
// deleted: category=sports
doPages(15, 'page-news.php', '', 85);
?>
<?php endwhile; ?>
<?php endif; ?>
</div>
</div>
<?php get_sidebar(); ?>
</div>
</div>
<?php get_footer(); ?>
Hi, I am using a freeware paging and customizing according to my needs. Can anyone help me in setting the next page ?
If you press [2], the next page, it will carries you to
http://ocklaw.com/new/news/page-news.php?page=2
How am I suppose to set the next page ? How ?
At this point, I am confuse where is the next page come from ?