How To Make Page Links For Each Pages
RegisterLogin
How To Make Page Links For Each Pages
Post Description: How To Make Page Links For Each Pages
Tags: How, To, Make, Page, Links, For, Each, Pages
This Post Was Posted On Oct 11, 2009 By Webune Tutorials #2538
Post Description: How To Make Page Links For Each Pages
Tags: How, To, Make, Page, Links, For, Each, Pages
This Post Was Posted On Oct 11, 2009 By Webune Tutorials #2538
How To Make Page Links For Each Pages by Webune Tutorials
today we are going to show you how to make links for each page. for example, have you noticed when you google something, at the bottom there is always links for each page like for page 1, page 2 etc...
Using PHP you can accomplish this. we are going to use a function to make it easy.
so what do you need for this, you are going to need PHP on your website for this script to work. first, open a text editor. i am using a windows xp computer so i will use notepad. open a blank notepad and copy and paste the following code:
<div style="float:left;padding-left:10px;">
<a href="http://www.webune.com">
<img src="http://www.webune.com/images/headers/default_logo.jpg" border="0" align="Webune Logo">
</a>
</div>
<h1 style="float:left">Webune Pagination Function</h1>
<div style="clear:left;"></div>
<hr />
<?php
##################################
# YOU CAN CONFIGURE THIS #
$num_of_items = 200;
$items_per_page = 9;
$max_links = 10;
# END CONFIGURATION #
#################################
if($_GET['page_num']){
$page_num = $_GET['page_num'];
}else{
$page_num = 1;
}
?>
<h1>This Is Page: <span style="color:#F00;"># <? echo $page_num; ?></span></h1>
<strong>example:</strong> <br>
<strong>number of items</strong> = <? echo $num_of_items; ?><br>
<strong>number of items per page</strong> = <? echo $items_per_page; ?><br>
<strong>number of links per page</strong> = <? echo $max_links; ?><br>
<?php
###### START PAGINATION FUNCTIONS ######
function pagination_link($id, $page_num){
return $_SERVER['PHP_SELF'].'?page_num='.$page_num;
}
function pagination($num_of_items, $items_per_page, $id, $page_num, $max_links){
$total_pages = ceil($num_of_items/$items_per_page);
if($page_num) {
if($page_num >1){
$prev = ' <a href="'.pagination_link($id, ($page_num -1 )).'">< PREV</a> ';
$first = '<a href="'.$_SERVER['PHP_SELF'].'"><< First Page</a>';
}
}
if($page_num <$total_pages){
$next = ' <a href="'.pagination_link($id, ($page_num+1)).'">NEXT ></a> ';
$last = ' <a href="'.pagination_link($id, $total_pages).'">Last Page >></a> ';
}
echo $first;
echo $prev;
$loop = 0;
if($page_num >= $max_links) {
$page_counter = ceil($page_num - ($max_links-1));
}else{
$page_counter = 1;
}
if($total_pages < $max_links){
$max_links = $total_pages;
}
do {
if($page_counter == $page_num) {
echo ' <strong>'.$page_counter.'</strong> ';
}else{
echo '<a href="'.pagination_link($id, ($page_counter)).'">'.$page_counter.'</a> ';
}
$page_counter++; $current_page=($page_counter+1);
$loop++;
}while ($max_links > $loop);
echo $next;
echo $last;
}
?>
<div align="center">
<?php
pagination($num_of_items, $items_per_page, $id, $page_num, $max_links)
?>
</div><br>
<br>
<div style="width:400px;">Thank you for trying out this tutorial.
We hope you have learned to create a pagination and
how you can make links for each page
<a href="http://www.webune.com">Click HerE For More Tutorials</a></div>
now save it as "pagination.php" {NOTE: be sure to also put the quotes so that notepad saves the file correctly, otherwise, it may save it as pagination.php.txt and we dont need the .txt at the end] now upload to your website which has PHP and test run it so see how it work.
we hope you liked this pagination php function. there are other ways to make page links for example, you can have pagination in jsp and also make javascript pagination, even pagination on wordpress. you can also have static pagination in css i have seen pagination in some joomla sites which use pagination in rails. next we are going to make ajax pagination. Ajax is more advanced because it uses javascript and PHP. visit us soon for an update.
Leave Your Comments
Related Pages: [Add Your Website]
Post New Topic
Tim
#5491 1
i am trying to use this script to display only a certain amount of article posts on blog-like pages. how would i do this?
Oct 02, 2011 Reply Report abuse
colbi
#3258 2
how to make my comment align about me box
Jan 15, 2010 Reply Report abuse
©2011 Webune Forums - Fri Dec 23, 2011 6:27 pm
Powered by: Webune Forums V3
Powered by: Webune Forums V3