Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Problem with pagination and offset together
I’ve recently run into a problem for a client site. I’m undecided whether calling it a bug or a lacking feature, so let me tell you.
Scenario: Imagine an archive page that looks like this homepage or this one. Let’s say that they list articles from the same section, but the first 3 articles has a different listform from the 4th and following ones. The first three have a photo, a title, an excerpt. Starting with the fourth the articles are listed without photos, only with title and excerpt.
TXP way of doing: Textpattern can easily do it using two different article tag in the archive template. The first article tag has a listform=“withphoto” and a limit=“3”. The second article tag has a listform=“nophoto”, a limit=“10”, and a mandatory offset=“3”. This way the three more recent articles will have the withphoto form, and starting with the fourth, they will be presented with a more minimal look. That’s fine. For an home page. But for an archive page that want the same listing?
The problem In an archive page you couldn’t present all the article in a page, if you have hundreds of them. You need a pagination. After the first, let’s say, 13 articles (3 of which with photo, and 10 without) you will click on a next page link and will be propted with other 13 articles: 3 of which with photo, and 10 without. That would be fine if… the list started with 14th articles in list, finishing the page with 26th. But this is not. Textpattern will list (in the second page) the 4th, the 5th and the 6th articles in archive (but you already seen them in the first page without photo…) with large photo. And, then, the 14th, 15th… to 23th articles in list without photo. Say goodbye to chronological order!
What cause the problem? The problem is somewhat expected, as the article tag can’t know how many articles in total are listed in the first page. So for any article tag it is assumed the limit attribute as the total number of article listed in one page. This is usually true, but not in a special case like this one: you should consider as limit the total number of articles listed by all article tags in the template.
A possible solution I’ve managed to solve the problem my own, hacking not the source code of txp, but the code of an article plugin I used. The solution I found involved a new attribute, that I called total_listed. In this attribute you may set the total number of listing in one page. You set this in any article tag you use in page. This way you can change the function that create the pages. Default for total_listed=0. In the function, check if it’s > 0. If it is, then use the modified formula for calculating pagination. Else use the old one.
The new formula I used is this:
....
// Paging
if (!$iscustom and !$issticky) {
$total = safe_count('textpattern', $where) - $offset;
$numPages = ceil($total/$pageby);
$pg = (!$pg) ? 1 : $pg;
// ====== This is the modification: ====================
if (($total_listed > 0) && ($pg >1)) {$pgoffset = $offset + $total_listed.', ';} else {
$pgoffset = $offset + (($pg - 1) * $pageby) . ', ';}
....
This is a possible solution among others, you may find a more elegant one. This should be done in the doArticles Function, I suppose (not sure). I prefer not to change the code of txp, but it would be great if in future version this could be added to the basic capabilities of textpattern.
Is this really needed? I think that this kind of layout for archives is fairly uncommon in blog template. But it may be used for more complex sites, for magazines, newspaper, etc. Maybe it is not common at all, if nobody discovered the issue before. But if you support the offset attribute for listing, you should also allow for his correct usage among multiple pages, I argue. Anyway, this should make sense for some layout, and actually there isn’t another way to do it the right way. So this is a sort of limitation of txp possibilities.
Disclaimer: If there is an easier way to accomplish the scenario, then forget about it and point me to the right solution, thank you!
Sorry for the long post and the bad english. Feel free to ask for clarifications.
Z-
Last edited by Zanza (2007-02-08 19:50:06)
Offline
Re: Problem with pagination and offset together
Is this something that the pageby
attribute does not handle properly?
Shoving is the answer – pusher robot
Offline
Re: Problem with pagination and offset together
So it looks like I’m a dumb! :) I never used that before, and I didn’t know about his existance, and I suppose I’d never understood his function without having this problem… Not tried, but seem just the same as my modification. :)
Luckily I wrote the disclaimer, because I know that you txp guys are always amazing me. :) Thanks a lot, Hakjoon, and sorry for the annoyance!…
Z-
Offline
Re: Problem with pagination and offset together
My favorite solution to a problem is realizing that the problem has already been solved :)
Last edited by hakjoon (2007-02-08 21:59:10)
Shoving is the answer – pusher robot
Offline