Textpattern CMS support forum

You are not logged in. Register | Login | Help

#21 2013-03-27 16:52:13

etc
Developer
Registered: 2010-11-11
Posts: 2,946
Website

Re: etc_pagination: paginate everything

Hi Jonathan, <txp:article_custom /> paginates very badly, but you can achieve it with a little help from etc_query (see here). Try to put this in your page form to paginate <txp:article_custom section="your_section" /> by 5:

<!-- count the pages -->
<txp:etc_query name="numPages" data="SELECT CEILING(count(*)/5) AS numPages FROM textpattern WHERE Status=4 AND Section='your_section'" />

<!-- navigation bar -->
<txp:etc_pagination pages='<txp:variable name="numPages" />' pgcounter="page" />

<!-- display the appropriate page -->
<txp:article_custom section="your_section" limit="5" offset='<txp:etc_query data="{?page|0|intval.-1.*5}" globals="_GET" />' />

Last edited by etc (2013-03-30 17:13:35)


etc_[ query | search | pagination | date | tree | cache ]

Offline

#22 2013-03-28 00:58:23

jstubbs
Moderator
From: Hong Kong
Registered: 2004-12-13
Posts: 2,392
Website

Re: etc_pagination: paginate everything

Thanks Oleg – I’ve given it a first go but run across probably a simple problem to resolve. Heres the code I’m using:

<!-- count the pages -->
		<txp:etc_query name="numPages" data="SELECT CEILING(count(*)/5) AS numPages FROM textpattern WHERE Status=4 AND Section='<txp:if_section name="news">news,blog,potw,six-innings<txp:else /><txp:section /></txp:if_section>'" />

		<txp:article_custom section='<txp:if_section name="news">news,blog,potw,six-innings<txp:else /><txp:section /></txp:if_section>' offset='<txp:etc_query data="{?page|0|intval.-1.*5}" globals="_GET" />'>

....Article stuff here....

<txp:if_article_list>
<txp:if_variable name="numPages" value="">
		<txp:else />
<div id="newer-older" class="text-center">
	<txp:etc_pagination pages='<txp:variable name="numPages" />' pgcounter="page" prev="Previous" next="Next" range='<txp:adi_if_mobile>2<txp:else />10</txp:adi_if_mobile>' wraptag="" break="" />
</div>
</txp:if_variable>
</txp:if_article_list>

What I’m getting is no pagination output. Just the newer-older div. I’ve tried removing the <txp:if_variable name> block but that doesn’t work either. There is something in the etc_pagination call that is throwing it off.

Second issue is that the article_custom is now displaying 10 articles in an individual article page – that didn’t happen before. I guess I could add if_individual logic, but would like to understand why the etc_query tag in the article_custom call changes the output of articles….

Offline

#23 2013-03-28 08:27:04

jstubbs
Moderator
From: Hong Kong
Registered: 2004-12-13
Posts: 2,392
Website

Re: etc_pagination: paginate everything

Seems the variable is not being set properly:

<txp:if_variable name="numPages" value="">
			[<txp:if_variable name="numPages" value="">: false]
			<txp:etc_pagination pages='<txp:variable name="numPages" />' pgcounter="page" prev="Previous" next="Next" range='<txp:adi_if_mobile>2<txp:else />10</txp:adi_if_mobile>' wraptag="" break="" />
				[attribute 'pages']
				<txp:variable name="numPages" />
					[<txp:variable>: Unknown variable 'numPages']
				[/attribute]
				[attribute 'range']
				<txp:adi_if_mobile>
					[<txp:adi_if_mobile>: false]
				</txp:adi_if_mobile>
				[/attribute]
				[<txp:etc_pagination pages='<txp:variable name="numPages" />' pgcounter="page" prev="Previous" next="Next" range='<txp:adi_if_mobile>2<txp:else />10</txp:adi_if_mobile>' wraptag="" break="" />: false]
		</txp:if_variable>

I got the article_list and individual pages sorted out, just used forms instead inside calls to article_custom and article. So now, its just list pagination.

Offline

#24 2013-03-28 09:10:12

etc
Developer
Registered: 2010-11-11
Posts: 2,946
Website

Re: etc_pagination: paginate everything

Jonathan, etc_query uses the raw MySQL syntax for DB queries, so Section='news,blog,potw,six-innings' looks for the section literally named news,blog,potw,six-innings. Try to replace the first query by

<!-- count the pages -->
<txp:etc_query name="numPages"
	data='SELECT CEILING(count(*)/5) AS numPages FROM textpattern WHERE Status=4 AND Section IN (<txp:if_section name="news">"news","blog","potw","six-innings"<txp:else />''<txp:section />''</txp:if_section>)' />

and then (without if_variable)

<txp:etc_pagination pages='<txp:variable name="numPages" />' pgcounter="page" prev="Previous" next="Next"
	range='<txp:adi_if_mobile>2<txp:else />10</txp:adi_if_mobile>' wraptag="div" class="text-center" />

Edit: you’ll probably have to replace “six-innings” by “six\-innings”, but I am not sure.

Last edited by etc (2013-03-28 09:14:34)


etc_[ query | search | pagination | date | tree | cache ]

Offline

#25 2013-03-28 10:45:59

jstubbs
Moderator
From: Hong Kong
Registered: 2004-12-13
Posts: 2,392
Website

Re: etc_pagination: paginate everything

Thanks Oleg! Looking great now – thanks for the instruction re the raw MySQL queries – its good to learn about this amazing little plugin you have written – thank you for that! There was no need to escape six\-innings – it didn’t work. six-innings was fine!

Offline

#26 2013-03-28 11:49:34

etc
Developer
Registered: 2010-11-11
Posts: 2,946
Website

Re: etc_pagination: paginate everything

Glad you have it working, just call if something gets weird!

Slightly OT for devs: the first counting query would be unnecessary if <txp:article_custom /> supported pgonly attribute in some sense. For example, <txp:article_custom pgonly="numPages" /> could store the number of pages in <txp:variable name="numPages" />. I am not very hot about tight integration of article_custom pagination into etc_pagination, this would yield too much code replication.

Edit: or if <txp:article_custom pgonly="1" /> returned the number of pages…

Last edited by etc (2013-03-28 11:58:03)


etc_[ query | search | pagination | date | tree | cache ]

Offline

#27 2013-03-30 16:08:39

etc
Developer
Registered: 2010-11-11
Posts: 2,946
Website

Re: etc_pagination: paginate everything

Version 0.3.5: added new (undocumented, but self-explanatory) <txp:etc_numpages /> and <txp:etc_offset /> tags, to ease <txp:article_custom /> pagination. The problem above can be solved without etc_query now:

<!-- navigation bar -->
<txp:etc_pagination pgcounter="page"
	pages='<txp:etc_numpages section="news,blog,potw,six-innings" limit="5" />' />

<!-- display the appropriate page -->
<txp:article_custom section="news,blog,potw,six-innings" limit="5"
	offset='<txp:etc_offset pageby="5" pgcounter="page" />' />

You don’t need them for <txp:article /> pagination.

P.S. I still think that <txp:article_custom pgonly="1" /> would be better, so <txp:etc_numpages /> hopefully is only temporary solution.


etc_[ query | search | pagination | date | tree | cache ]

Offline

#28 2013-03-31 00:52:30

jstubbs
Moderator
From: Hong Kong
Registered: 2004-12-13
Posts: 2,392
Website

Re: etc_pagination: paginate everything

Great! I’ll give it a shot later and report back. Thanks Oleg!

Offline

#29 2013-03-31 08:41:51

jstubbs
Moderator
From: Hong Kong
Registered: 2004-12-13
Posts: 2,392
Website

Re: etc_pagination: paginate everything

Ok Oleg – its working. Here’s what I had to do:

Page template:

<txp:article_custom section='<txp:if_section name="news">news,blog,potw,six-innings,photos<txp:else /><txp:section /></txp:if_section>' limit="10" offset='<txp:etc_offset pageby="10" pgcounter="page" />' form="news_list" />	

Pagination form:

<div id="newer-older" class="text-center">
	<txp:etc_pagination pgcounter="page" pages='<txp:etc_numpages section='<txp:if_section name="news">news,blog,potw,six-innings,photos<txp:else /><txp:section /></txp:if_section>' limit="10" />' prev="Previous" next="Next" range='<txp:adi_if_mobile>2<txp:else />10</txp:adi_if_mobile>' wraptag="" break="" />
</div>

Thanks a lot for this – much cleaner.

Offline

#30 2013-05-08 16:59:24

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,152

Re: etc_pagination: paginate everything

Hi Oleg,
I’m trying to create prev/next links for a txp:article tag, ordered by position (the stm_article_order DB column) and would expect to have chosen the easier one of the two article tags and be able to alter some attributes and in this way somehow get me there. But I’ve no luck: the two examples taken from the help output nothing although I’ve placed them in the same form that the native prev/next tags work in.
Please nudge me in the right direction. (TXP is 4.5.4, etc_pagination is v0.3.5)


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

Board footer

Powered by FluxBB