Pagination - the Awkward Way!

5 posts by 2 authors in: Forums > CMS Builder
Last Post: August 19, 2010   (RSS)

I want to set-up a form of pagination between (detail) pages assigned to the current $selectedCategory. I appreciate there is already a method of doing this, along the lines of...

.....

<a href="<?php echo $itemRecordMetaData['prevPageLink'] ?>">&lt;&lt; prev</a>

.....

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

.....

<a href="<?php echo $RecordMetaData['nextPageLink'] ?>">next &gt;&gt;</a>

.....


Although this structure is fine, it's intended for use on list pages so requires certain modifications to the list() code to make it work.

Also, the way in which the next/prev links function is different to the normal approach and can cause problems. (i.e. such pages do not use/require 'where' => whereRecordNumberInUrl(1) ).

My question is; can the pagination structure outlined above be configured in such a way as to generate normal links which do use whereRecordNumberInUrl(1)?

:oS

Perchpole

Re: [Perchpole] Pagination - the Awkward Way!

By Jason - August 18, 2010

Hi Perchpole,

Yes, you can create custom links for use in the pagination for pages that do use whereRecordNumberInUrl().

The best way to format your link would be like this:
myPage.php?num=RECORDNUMBER&page=PAGENUMBER

If you're using a format that doesn't use the num variable in the URL string (such as myPage.php?my-title-NUMBER), you can still do this by making sure the record number is the last number in the string (ie. myPage.php?page=PAGENUMBER&my-title-NUMBER)

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

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

Re: [Jason] Pagination - the Awkward Way!

Hi, Jason -

Thanks for your tips but I think there's a bit more to it than that...

The problem is how to generate/assign the correct page number to the link.

Part of the pagination code block looks like this...
<?php foreach (range(1,$itemRecordMetaData['totalRecords']) as $page): ?>
<?php if ($page == $current_page): ?>
<strong><?php echo $page; ?></strong>
<?php else: ?>
<a href="./index.php?category=<?php echo $selectedCategory['num'] ?>&page=<?php echo $WHAT['num'] ?>">Link</a>
<?php endif ?>
<?php endforeach; ?>

The foreach loop does not pass down any record information - so there is no way to pull the record 'num' into the link.

If I were to use $page it would just be an arbitrary number which wouldn't match the actual record number as required by whereRecordNumberInUrl(1).

:0S

Perch

Re: [Jason] Pagination - the Awkward Way!

Hi, Jason -

No worries. I spent much of last night and almost all of today pulling the structure apart and rebuilding it again how I want it. The result works quite well and I've learned a lot along the way into the bargain.

Essentially, it's a pagination system for detail pages. It looks identical to the method raised by Damon, here...

page count at bottom with prev next links

...but uses different data to set-up the page numbers and generate the links.

Once I've tidied things up I'll give the code a proper run out in the forum...

:0)

Perch