Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Re: List pagination
Gocom wrote:
not really sure about the error supression tho
To be honest I just copied ‘n’ pasted that from another tag. You’re right, it’s ugly. There should probably be an assert_page()
function that triggers a warning if $thispage
is NULL. Then we could remove the error suppression, safe in the knowledge that we’re on a list page.
There is no loop with globals, and functions returning the global.
Not quite sure what you mean, sorry. Could you give an example for my s-l-o-w brain to comprehend?
What about
if_first/last
?
Good idea, makes sense. My take on it:
function if_first_page($atts,$thing) {
global $thispage;
// assert_page(); // TODO: add this to lib/txplib_misc.php
return parse(EvalElse($thing, (empty($thispage['pg']) or $thispage['pg'] == 1) ));
}
function if_last_page($atts,$thing) {
global $thispage;
// assert_page();
return parse(EvalElse($thing, ($thispage['pg'] == $thispage['numPages']) ));
}
I kinda wondered if a sort of ‘if_page’ tag might be useful so you could use it to only show the pagination block if the number of pages (or the number of results?) exceeds a certain number. Not quite sure how that tag would be written though. Ideas? Perhaps smd_if is good enough here, or we’ll start getting into some very complicated tagging scenarios…
jsoo
Hey, now range
has merit. I like that one.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
Re: List pagination
Range seems better. How about scope
?
Stuart
In a Time of Universal Deceit
Telling the Truth is Revolutionary.
Offline
Re: List pagination
Bloke wrote:
Not quite sure what you mean, sorry. Could you give an example for my s-l-o-w brain to comprehend?
Sure.
function one($atts,$thing) {
global $this;
loop() {
$this['foo'] = $bar;
$out[] = parse($thing);
}
}
function two() {
global $this;
return $this['foo'];
}
<txp:one>
<txp:two />
</txp:one>
I don’t have any programmer’s dictionary degree.
Last edited by Gocom (2010-05-05 17:02:17)
Offline
#16 2010-05-05 19:24:51
- rsilletti
- Moderator
- From: Spokane WA
- Registered: 2004-04-28
- Posts: 707
Re: List pagination
I backed this into plugin code and used your examples at the top of this thread. I plugged it into a site using the current download, the only caveat i see there is the ctype array element – and that should simply be disregarded. The results I’m getting are a little unexpected, as follows:
- index page *
Results: 392. Page 1 of 79
1 · 2 · 3 · 4
First « 1 2 3 4 » Last
- after navigation to page 2 *
Results: 392. Page 2 of 79
1 · 2 · 3 · 4 · 5
First « 1 2 3 4 5 » Last
- after navigation to page 3 *
Results: 392. Page 3 of 79
1 · 2 · 3 · 4 · 5 · 6
First « 1 2 3 4 5 6 » Last
- after navigation to page 4 *
Results: 392. Page 4 of 79
1 · 2 · 3 · 4 · 5 · 6 · 7
First « 2 3 4 5 6 7 » Last
…
I haven’t gotten around to plugging in attributes or flexing out tags for testing yet, but I think this fills a bit of a vacuum in the core code. If it can be this neatly it should be there.
Offline
Re: List pagination
rsilletti wrote:
the only caveat i see there is the ctype array element
Yeah, that only comes into play if you’re in a /category/some-cat
list page. I added a check in the latest version of <txp:paging />
to omit it if you’re not on a category page but that’s probably a little unreasonable. The check should be in the pagelinkurl()
function I just forgot to trap it when I added the ctype thing. I will add the extra check there instead and remove it from this tag.
The results I’m getting are a little unexpected
The code I used above is a little bit unrealistic in the following regards:
- The examples will look odd if used together: the 1st example shows 3 pages either side of the current page, whereas the 2nd uses 2 before and 3 after
- The First/Last/Next/Prev things are always visible. In reality you might use the conditional tags if_first_page / if_last_page to hide it when not needed or at the very least take some other action to remove the anchors when at the list extremities
- There’s no visual indication that there are missing pages when you get towards the middle of the list. Most implementations I’ve seen use an ellipsis — like in this forum — to show the missing pages at either end of the central block. I would like this tag suite to be capable of displaying some character(s) of your choosing to indicate ‘missing’ pages but I’m not quite sure how this should be handled. Any ideas welcome.
I think this fills a bit of a vacuum in the core code. If it can be this neatly it should be there.
I agree :-) If we can hone it to perfection over the next few days and there are no further objections I think it may sneak into the core. If not, I can always make a plugin out of it.
I have a few other things to fix up in the meantime: the aformentioned rogue ctype link is one, along with a few other related adjustments that I’ve been holding off until I was sure that the whole ctype thing was acceptable.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
#18 2010-05-05 20:06:00
- rsilletti
- Moderator
- From: Spokane WA
- Registered: 2004-04-28
- Posts: 707
Re: List pagination
I had a feeling that the paging was working right and that it had something to do with prev/next boundaries from the current page. I’ll keep testing this as time permits and post here if I see anything untoward. Thanks, it will be nice to have this.
Offline
Re: List pagination
New version uploaded in the first post, and OP updated:
- offset attribute is now range (thanks jsoo)
<txp:if_first_page>
and<txp:if_last_page>
added- support put in ready for
assert_page()
— commented out for now until function written — so the tag will trigger a warning if used on an individual article page - ctype bug fixed for sure this time
Gocom
Thanks for the example. I see what you mean. No, there’s no container tag for this one as it would mean a slew of extra tags like txp:page, txp:result_count, txp:prev_page, txp:next_page, and so on. Since you’re often dealing with lists and things and — I assume — will quite often want to join elements together, I figured that being able to string a list of item
s together and join them in one tag was a) more efficient, b) less typing, c) more logical, than using a bunch of tags which, although more TXPish, would probably be more unwieldy in the long run.
I reserve the right to be wrong :-)
thebombsite
scope
is an interesting one, but since there’s the possibility of a core tag called <txp:scope>
at some point — and scope also has other programmery connotations — I’ve shied away from it and gone with jsoo’s range
suggestion instead. Hopefully that’ll mean more to more people and not scare them off the tag!
all
If anybody has any further thoughts on this, especially regarding its usefulness in the core, whether a generic ‘if page’ can become a reality, whether the tags hold up under stress testing in a site, and of course who can come up with the funkiest nav bar then please holler.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
Re: List pagination
No problem. So pray tell where <txp:scope>
might pop up then.
Stuart
In a Time of Universal Deceit
Telling the Truth is Revolutionary.
Offline
Re: List pagination
thebombsite wrote:
So pray tell where
<txp:scope>
might pop up then.
*shrug* ask Sam, he proposed it. I just work here :-)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
Re: List pagination
Minor adjustment to the opening post and the download:
- Changed
ctype
tocontext
in line with latest SVN commit - Added
escape
attribute (default:html
) - Added
<txp:if_pages>
as a convenience to allow you to wrap the entire nav block so it only appears when there is > 1 page of results
I’ve had no luck with the ‘gap’ thing. I tried adding prev_gap
and next_gap
items but if you use them separately you need to remember to kep the range
attributes in step, which is a bind.
If instead they are automatically added to the existing prev
and next
items then you lose the ability to alter the character used/set escaping (by default it’d be …
which would require escape=""
… again, not a very user friendly solution). You also lose the ability to turn them off unless a new attribute is introduced, which would only be applicable to the next
and prev
items. It’s bad enough having range
which is only applicable to next
and prev
, without introducing more attributes for the sake of it.
Investigation ongoing. Perhaps this really is plugin territory, or a rethink of the way it’s implemented here. Any help/ideas appreciated.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
Re: List pagination
How about a popup menu that allows you to jump directly to a page — as seen at the bottom of this site.
Mark
Offline
Re: List pagination
mwr wrote:
How about a popup menu that allows you to jump directly to a page
Good idea, and actually the original pagination tag was most of the way there already. I’ve just added a convenience item="all"
that gets all the page numbers. The tricky thing here is to get it to select the current page in the list. The paging tag can’t do that, and it’s rather tough to put it in there without making things much more complicated. A fairly simple alternative is to get the tag to do the HTML part and then throw some jQuery on the page to position the current page in the select list:
<form action="">
<select name="pg" id="jumpto">
<txp:paging item="all" break="option" link="0" />
</select>
<input type="submit" value="Jump to page">
</form>
<script type="text/javascript">
jQuery(function() {
var currpage = '<txp:paging item="page" link="0" />';
jQuery("#jumpto option").each(function() {
if (jQuery.trim(jQuery(this).text()) == currpage) {
jQuery(this).attr("selected", true);
}
});
});
</script>
If it weren’t for the fact you can’t add a ‘name’ attribute to the paging tag (at the moment), you could generate the entire <select>
in one line instead of having to type some HTML as well. Of course, if you prefer an onchange
selector you can do that instead of the submit button. The jQuery just grabs the current page, iterates over the options list and finds the one that matches. I’m sure there’s a more efficient way of doing that but jQuery’s not my bagel.
Hope that helps somewhat. If anybody has any comments on this method please share them.
Everyone
The latest version of the tag suite has the following changes:
- New
all
item, as mentioned above - New attribute
separator
. This is the text you want to use to visually separate the central prev/next paging area from its anchored numbers either side. The example below shows how you could use it - New conditional
if_page
that takes the attributevalue
. This allows you to test if you are on any given page. Provide one or more pages as a list and it’ll take action if the current page number matches one of them. Supports<txp:else />
Here’s an example using the new separator
attribute and a frivolous use of <txp:if_page>
:
<p class="direct_nav">
<txp:paging item="first" linktext="First" />
<txp:newer showalways="1">«</txp:newer>
<txp:paging item="prev" break=" " separator="… " />
<txp:paging item="page" link="0" /><txp:if_page value="5"> HELLO </txp:if_page>
<txp:paging item="next" break=" " separator=" …" />
<txp:older showalways="1">»</txp:older>
<txp:paging item="last" linktext="Last" />
</p>
On page 6, that would render the following:
First « … 4 5 6 7 8 … » Last
Let me know if this is a better/worse/more confusing/useless alteration, or any other random related thoughts you may have.
Last edited by Bloke (2010-05-13 00:33:11)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline