List page - page links/navigation

8 posts by 4 authors in: Forums > CMS Builder
Last Post: July 6, 2009   (RSS)

Hi,

On a list page, w have the navigation between the pages at the bottom (i.e. << previous page, page 1, page 2, next page >> etc etc).

Is there anyway to limit the number of page X links there are, for example, going from:

<< prev - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 next >>

to

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

The code for the page numbers is as follows:

<?php foreach (range(1,$productsMetaData['totalPages']) as $page): ?>
<?php echo $page; ?>
<?php endforeach; ?>


If there is a way to limit the foreach in the above, so you just get 1,2,3,4,5...

The main issue would then be that when you are on page 10 (with page links limited to 5), instead of showing the first 5 pages, it needs to show 5 pages around 10...

i.e.

<<prev 8,9,10,11,12 next >>


You see this idea quite alot around on various sites, for example:

http://www.readitswapit.co.uk/TheLibrary.aspx?CategoryID=-1&CategoryName=All+Fiction&PageID=21&TimeSlot=633685482000003118&BookType=999

You see the page nav has 10 either side of where you are.

Any ideas?

Many thanks in advance
Rob

Re: [rjbathgate] List page - page links/navigation

By Dave - January 26, 2009

Hi Rob,

Try something like this:

<?php foreach (range(1,$productsMetaData['totalPages']) as $page): ?>
<?php $maxPageRange = 5; ?>
<?php if ($page > ($productsMetaData['totalPages'] + $maxPageRange)) { continue; } ?>
<?php if ($page < ($productsMetaData['totalPages'] - $maxPageRange)) { continue; } ?>

<?php echo $page; ?>
<?php endforeach; ?>


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

Re: [Dave] List page - page links/navigation

Hi,

Thanks Dave, seems like it's almost there, but it's just showing the last 6 page numbers, rather than either side of what page you're on.

So when on page 3, it's showing the last 6 pages (say 40,41,42,43,44,45,46), instead of 1,2,3,4,5,6.

I will email you the URL for a demo.

Thanks
Rob

Re: [rjbathgate] List page - page links/navigation

By Dave - January 27, 2009

Rob,

Ahh, ok. We need the current page number. Display the variables in $productsMetaData like this:

<xmp><?php print_r($productsMetaData); ?></xmp>

Then find the one that has the current page number and replace $productsMetaData['totalPages'] with it in this code:

<?php if ($page > ($productsMetaData['totalPages'] + $maxPageRange)) { continue; } ?>
<?php if ($page < ($productsMetaData['totalPages'] - $maxPageRange)) { continue; } ?>

I think it's called $productsMetaData['page']

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

Re: [Dave] List page - page links/navigation

Hi Dave,

Yes, it is 'page'

This code works a treat:

<?php foreach (range(1,$productsMetaData['totalPages']) as $page): ?>

<?php $maxPageRange = 4; ?>
<?php if ($page > ($productsMetaData['page'] + $maxPageRange)) { continue; } ?>
<?php if ($page < ($productsMetaData['page'] - $maxPageRange)) { continue; } ?>

<?php echo $page; ?>

<?php endforeach; ?>


This gives you 4 pages either side of what page you are on.

Thanks Dave!
Rob

Re: [rjbathgate] List page - page links/navigation

By Dave - January 29, 2009

Great, glad to hear it's working! :)
Dave Edis - Senior Developer
interactivetools.com

Re: [HDLLC] List page - page links/navigation

By ross - July 6, 2009

Hi Jeff

Thanks for the update!

I think we might be getting a bit more advanced than we can handle in support. Would you mind sending me an email through consulting@interactivetools.com? We'll go over the options from there.

Thanks!
-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/