page count at bottom with prev next links

16 posts by 7 authors in: Forums > CMS Builder
Last Post: June 13, 2011   (RSS)

By Codee - February 1, 2010 - edited: March 8, 2010

the default CMSB code produces this at the bottom of the pages:

<< prev - page 1 of 5 - next >>

How can I make it offer a clickable page number, like:

<< prev - page 1 of 5 - next >> go to page #__

or

<< prev - page 1 - next >> 1, 2, 3, 4, 5

so that the end users can click to the page they want or enter in the page number they want?

Thanks!

Re: [equinox69] page count at bottom with prev next links

By Damon - February 2, 2010 - edited: February 4, 2011

Here is some code to generate this type of pagination:

<< prev 1 2 3 4 next >>

Just replace "$newsMetaData" with your section name.
<!-- START PAGINATION CODE -->
<?php if ($newsMetaData['prevPage']): ?>
<a href="<?php echo $newsMetaData['prevPageLink'] ?>">&lt;&lt; prev</a>
<?php else: ?>
&lt;&lt; prev
<?php endif ?>

<?php
if (@!$_GET['page']): $current_page = "1";
else: $current_page = $_GET['page'];
endif; ?>

<?php foreach (range(1,$newsMetaData['totalPages']) as $page): ?>
<?php if ($page == $current_page): ?>
<strong><?php echo $page; ?></strong>
<?php else: ?>
<a href="?<?php echo http_build_query(array_merge($_REQUEST, array( 'page' => $page ))) ?>"><?php echo $page; ?></a>
<?php endif ?>
<?php endforeach; ?>

<?php if ($newsMetaData['nextPage']): ?>
<a href="<?php echo $newsMetaData['nextPageLink'] ?>">next &gt;&gt;</a>
<?php else: ?>
next &gt;&gt;
<?php endif ?>
<!-- /END PAGINATION CODE -->


You can also see all the $newsMetaData variables available to use with this code:
<?php showme($newsMetaData); ?>

Updated: to include Chris's code that will preserve all the form fields submitted to the page, but will also set 'page' to $page
Cheers,
Damon Edis - interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Damon] page count at bottom with prev next links

By Codee - February 2, 2010

Rockin' Damon! Thanks!

Additional help needed, was Re: [Damon] page count at bottom with prev next links

By Codee - March 6, 2010

Hi Damon or any other CMSB helpful people:

According to the above code the pagenumbers appear at the bottom of the inventory listings pages and that generally works great...BUUUUTTTT.....

when someone searches by a certain field, for example
http://www.sitename.com/inventoryList.php?listing_type=private%20party

the part of the url after the question mark disappears on the additional pages and it brings up ALL the listings. Is there a way to have the numbers at the bottom list out based upon what was in the originating URL so this doesn't occur? so if there were only 3 or 4 pages for private party ads then clicking on any of the 1, 2, 3 or 4 would display the relevant results?

thanks in advance!

Re: [equinox69] Additional help needed, was Re: [Damon] page count at bottom with prev next links

By Dave - March 8, 2010

Hi Terry,

One way is to manually construct the url so it passes forward any possible values, such as:

<a href="?page=<?php echo $page; ?>&listing_type=<?php echo urlencode(@$_REQUEST['listing_type']) ?>"><?php echo $page; ?></a>

Let me know if that works for you.
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Additional help needed, was Re: [Damon] page count at bottom with prev next links

By Codee - October 11, 2010

This works for any "listing_type" but what if they search by a different field or used a search box that checks 7 possible fields? How do we accomplish using whatever they had searched by and received results?

Re: [equinox69] Additional help needed, was Re: [Damon] page count at bottom with prev next links

By Chris - October 12, 2010 - edited: October 12, 2010

Hi equinox69,

This code will preserve all the form fields submitted to the page, but will also set 'page' to $page:

<a href="?<?php echo http_build_query(array_merge($_REQUEST, array( 'page' => $page ))) ?>"><?php echo $page; ?></a>

Does that help? Please let me know if you have any questions.
All the best,
Chris

Re: [chris] Additional help needed, was Re: [Damon] page count at bottom with prev next links

By Codee - October 12, 2010

That not only helps, but it works! Thanks Chris!

Re: [equinox69] Additional help needed, was Re: [Damon] page count at bottom with prev next links

By andybarn - June 8, 2011

Hi Chris

This works for me too - great!

However I hope you don't mind me jumping in on this thread but when I have for example 20 pages that match my search I get the following listed accross the page:-

<< < 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 > >>

Is there a way to limit the number of pages showing to something like you have on this forum so it shows:-
<< < 1 2 3 4 5 6 7 8 9 ... 20 > >>


Thanks for your help

Andy