Textpattern CMS support forum

You are not logged in. Register | Login | Help

#11 2010-05-05 11:53:42

Gocom
Plugin Author
Registered: 2006-07-14
Posts: 4,524
Website

Re: List pagination

Looks cool. I’m not really sure about the error supression tho. Isset check? It might be slower tho and works differently with NULL, right?

As I said, and I say again, it’s cool. Bit differently from most TXP tags. There is no loop with globals, and functions returning the global.

What about if_first/last?

function if_paging_last($atts,$thing) {
	global $thispage;
	/*
		Context check here?
	*/
	return parse(EvalElse($thing,(
		$thispage['pg'] <= $thispage['numPages']
	)));
}
function if_paging_first($atts,$thing) {
	global $thispage;
	return parse(EvalElse($thing,(
		!$thispage['pg'] or $thispage['pg'] == 1
	)));
}

And like for the actual pagination too. Wouldn’t require more than some global lifting to the loop and those function code. I’m not really sure if that code is helpful, like first and last page, but that for the pagination would. Same tags could be used too.

Something like:

$thispage['pg'] = $theItem;

To the loop or something and it kinda starts to work.

Last edited by Gocom (2010-05-05 12:05:48)

Offline

#12 2010-05-05 12:41:51

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,781
Website

Re: List pagination

Bloke wrote:

I know what you mean, it’s not quite ‘right’ to call it an offset even though it’s an offset either side of the current page. limit too has other connotations but it’s perhaps a better fit. width might also be a contender but that could be confusing. I notice you use window_size in soo_page_numbers. In this case the ‘width’ of the nav is really +/- a set amount from the central point and I couldn’t find a current attribute that fitted any better than offset; nor could I think of a new one that accurately described what the attribute did. Anybody have any bright ideas here?

window_size is simply a holdover from the old rsx_ plugin on which I initially based mine; I don’t suggest using it here. width, size, or range are the best short choices I can think of at the moment.


Code is topiary

Offline

#13 2010-05-05 13:33:01

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,523
Website

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

#14 2010-05-05 14:12:23

thebombsite
Plugin Author
From: Exmouth, England
Registered: 2004-08-24
Posts: 3,251
Website

Re: List pagination

Range seems better. How about scope?


Stuart – The BombsiteProText ThemesTextgarden

In a Time of Universal Deceit
Telling the Truth is Revolutionary.

Offline

#15 2010-05-05 17:01:32

Gocom
Plugin Author
Registered: 2006-07-14
Posts: 4,524
Website

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: 704

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

#17 2010-05-05 19:43:50

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,523
Website

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: 704

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

#19 2010-05-06 14:04:44

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,523
Website

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 items 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

#20 2010-05-06 21:00:05

thebombsite
Plugin Author
From: Exmouth, England
Registered: 2004-08-24
Posts: 3,251
Website

Re: List pagination

No problem. So pray tell where <txp:scope> might pop up then.


Stuart – The BombsiteProText ThemesTextgarden

In a Time of Universal Deceit
Telling the Truth is Revolutionary.

Offline

Board footer

Powered by FluxBB