Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#196 2017-03-20 09:26:34
Re: etc_pagination: paginate everything
etc wrote #304927:
You are already counting the articles with etc_query, right? Try to reuse the counter variable somehow. ;-)
Is that where I set the limit—within the etc_query? Or elsewhere? (I really appreciate your patience.)
textpattern.org :: find and share Textpattern resources
docs.textpattern.io :: Textpattern user documentation
Offline
#197 2017-03-20 10:37:01
Re: etc_pagination: paginate everything
No worries, I enjoy txp challenges. You can count pages with etc_pagination, but it would take an extra db query. Let’s try another way.
From a quick look at your page, the monthly archive is constructed before the main content? So, right after this block, <txp:variable name="counter" /> stores the total number of live articles from journal,briefs,about,words sections. The first invalid page number can be calculated and stored in <txp:variable name="nopage" /> with
<txp:etc_query name="nopage" data="{?counter|1|/200.intval.+2}" />
Now, replace (wherever needed) <txp:page_url type="pg" /> with
<txp:etc_query data='<txp:page_url type="pg" />' query="$min($|{?nopage}).max($|0)" />
to limit pg to nopage.
Offline
#198 2017-03-20 18:47:12
Re: etc_pagination: paginate everything
I would not have come up with that on my own >_< I think I’m absorbing the syntax and the concepts though. Thank you again. !
<txp:page_url type="pg" /> goes in the id of etc_cache, yes? So then I have a double-nested txp tag, and I think that’s what my page was balking at? So I made another variable:
<txp:variable name="pglimit"><txp:etc_query data='<txp:page_url type="pg" />' query="$min($|{?nopage}).max($|0)" /></txp:variable>
<txp:etc_cache id='dense_archivebydate<txp:variable name="pglimit" />'>
Seems to be working..was this right? Or what’s the proper/better way to do this?
textpattern.org :: find and share Textpattern resources
docs.textpattern.io :: Textpattern user documentation
Offline
#199 2017-03-20 20:25:49
Re: etc_pagination: paginate everything
alicson wrote #304945:
<txp:page_url type="pg" />goes in theidof etc_cache, yes? So then I have a double-nested txp tag, and I think that’s what my page was balking at? So I made another variable:
<txp:variable name="pglimit"><txp:etc_query data='<txp:page_url type="pg" />' query="$min($|{?nopage}).max($|0)" /></txp:variable>
That’s fine, though you can shorten it to
<txp:etc_query name="pglimit" data='<txp:page_url type="pg" />' query="$min($|{?nopage}).max($|1)" />
You can also simply use nested quotes:
txp <txp:etc_cache id='dense_archivebydate<txp:etc_query data=''<txp:page_url type="pg" />'' query="$min($|{?nopage}).max($|1)" />'>
Seems to be working..was this right? Or what’s the proper/better way to do this?
Ahem… does not seem to work on your site atm, but you are probably tweaking something? A more straightforward way is to directly modify txp internals instead of nopage and pglimit calculation:
<txp:php>
global $pretext, $variable;
$pretext['pg'] = max(1, min(intval($variable['counter']/200) + 2, $pretext['pg']));
</txp:php>
Then <txp:page_url type="pg" /> will be limited, so you can safely call
<txp:etc_cache id='dense_archivebydate<txp:page_url type="pg" />'>
But internals can change one day.
Offline
#200 2017-03-20 21:02:46
Re: etc_pagination: paginate everything
re: etc wrote #304947
Ooh double single quotes. That’s new for me.
For my own sense, is there a reason why an enduser (spam) can make up page numbers and slam the site that way? Or does it generally just not matter, except when one happens to have combinations of pagination and caching set up without having further accounted for queries of miscellaneous imaginary page numbers?
And what do the .max($|0) vs. the .max($|1) mean?
Thank you!
textpattern.org :: find and share Textpattern resources
docs.textpattern.io :: Textpattern user documentation
Offline
#201 2017-03-20 21:10:34
Re: etc_pagination: paginate everything
And yes it seems to be frozen again.
I have
<txp:variable name="numPgs"><txp:etc_numpages section="journal,briefs,about,words" pageby="500" /></txp:variable>
<txp:variable name="nopage"><txp:etc_query name="nopage" data="{?numPgs|1|/500.intval.+2}" /></txp:variable>
and
<txp:etc_cache id='dense_archivebydate<txp:etc_query data=''<txp:page_url type="pg" />'' query="$min($|{?nopage}).max($|1)" />'>
textpattern.org :: find and share Textpattern resources
docs.textpattern.io :: Textpattern user documentation
Offline
#202 2017-03-20 21:24:05
Re: etc_pagination: paginate everything
You divide by 500 twice. Try
<txp:variable name="numPgs" value='<txp:etc_numpages section="journal,briefs,about,words" pageby="500" />' />
<txp:etc_query name="nopage" data="{?numPgs|1|.+1}" />
Offline
#203 2017-03-20 21:39:23
Re: etc_pagination: paginate everything
alicson wrote #304948:
For my own sense, is there a reason why an enduser (spam) can make up page numbers and slam the site that way? Or does it generally just not matter, except when one happens to have combinations of pagination and caching set up without having further accounted for queries of miscellaneous imaginary page numbers?
I’m not a behavioral specialist, sorry. :-) In general it does not matter, but in your case etc_cache will create a record for every encountered (even invalid) pg value and try to update it later. This will take unnecessary time and space.
And what do the
.max($|0)vs. the.max($|1)mean?
Zero was a mistype, sorry. .max($|1) means for etc_query the maximum between 1 and the initial data passed by the chain:
<txp:etc_query data="2" query="$*2.+1.max($|3)" />
reads as 2 -> 2*2=4 -> 4+1=5 -> max(5, 3)=5.
Offline
#204 2017-03-20 21:49:53
Re: etc_pagination: paginate everything
I didn’t mean human-behavior-wise, I meant the structure of the site allowing for calls to imaginary pages that can cause a problem. ;) Sounds like the answer is the “create a record for every encountered (even invalid) pg value”.
Ahh txp:etc_query can assign like txp:variable; no wonder.
I think it’s good to go now, again with much thanks :)
textpattern.org :: find and share Textpattern resources
docs.textpattern.io :: Textpattern user documentation
Offline
#205 2017-03-20 22:29:42
Re: etc_pagination: paginate everything
Yep, your site seems to work faster now. Have you cached “Category slates” and “Months menu” too? Good luck, and glad to help! :-)
Offline
#206 2017-09-03 17:54:19
- GugUser
- Member

- From: Quito (Ecuador)
- Registered: 2007-12-16
- Posts: 1,477
Re: etc_pagination: paginate everything
Can someone please show me how I can bring these two elements to work? With section (or with category in an other case). All my experiments with the examples given in the help and in the forum gave no outputs.
I need only this basic pagination:
<txp:article_custom section="section-name" sort="LastMod desc" limit="12" form="form-name" />
<txp:etc_pagination range="0">
<p>Page {*} of {pages}</p>
</txp:etc_pagination>
Offline
#207 2017-09-03 20:20:53
Re: etc_pagination: paginate everything
GugUser wrote #306832:
Can someone please show me how I can bring these two elements to work? With section (or with category in an other case).
I guess you need to paginate <txp:article_custom /> list? Then you need to calculate the number of pages and offset:
<txp:article_custom section="section-name" sort="LastMod desc" limit="12" offset='<txp:etc_offset pgcounter="page" pageby="12" />' form="form-name" />
<txp:variable name="numPages" value='<txp:etc_numpages section="section-name" pageby="12" />' />
<txp:etc_pagination pages='<txp:variable name="numPages" />' pgcounter="page" range="0">
Page {*} of {pages}.
</txp:etc_pagination>
Adding page=3 (say) to url will land you on the 3rd page. Hope that helps.
Offline
#208 2017-09-03 22:20:18
- GugUser
- Member

- From: Quito (Ecuador)
- Registered: 2007-12-16
- Posts: 1,477
Re: etc_pagination: paginate everything
This works, many thanks.
This means that all for the pagination relevant attributes from <txp:article />, but unknown to <txp:article_custom />, can be placed in offset=' ', also pgonly?
That’s great, thank you.
I was confused, amongst other things, by this example, where there is no variable which transfers the data, and where pgonly="0" (without being an attribute of <txp:article_custom />) is outside the offset=' '.
Offline
#209 2017-09-04 02:51:44
- GugUser
- Member

- From: Quito (Ecuador)
- Registered: 2007-12-16
- Posts: 1,477
Re: etc_pagination: paginate everything
No, with pgonly in <txp:article_custom />, inside the offset=' ', it can’t work. I made it with en empty form.
In this manner the <txp:article_custom /> that is only for pgonly isn’t shown.
Offline
#210 2017-09-04 10:01:14
Re: etc_pagination: paginate everything
GugUser wrote #306839:
No, with
pgonlyin<txp:article_custom />, inside theoffset=' ', it can’t work.
FYI, in 4.7-dev <txp:article_custom section="some-section" pageby="12" pgonly /> returns the number of matching pages. We could also enhance its offset attribute to treat non-numeric values as page number url parameter. So
<txp:article_custom section="some-section" limit="12" offset="page" />
would output the 3rd page of 12 articles (articles 25—36) if url query string contains page=3.
Offline