Textpattern CMS support forum

You are not logged in. Register | Login | Help

#191 2017-03-17 15:27:40

alicson
Member
Registered: 2004-05-26
Posts: 465
Website

Re: etc_pagination: paginate everything

We win!! o^_^o

Very much thank you. I’m learning a lot also through all this implementation.


textpattern.org :: find and share Textpattern resources
docs.textpattern.io :: Textpattern user documentation

Offline

#192 2017-03-20 08:23:27

alicson
Member
Registered: 2004-05-26
Posts: 465
Website

Re: etc_pagination: paginate everything

How may etc_cache and etc_pagination play together? :) (Wrapping my date archives in etc_cache basically freezes pagination so that nothing other than the first page ever loads.)


textpattern.org :: find and share Textpattern resources
docs.textpattern.io :: Textpattern user documentation

Offline

#193 2017-03-20 08:35:55

etc
Developer
Registered: 2010-11-11
Posts: 3,199
Website

Re: etc_pagination: paginate everything

I think you need to create a cache block per page:

<txp:etc_cache id='archives-<txp:page_url type="pg" />' reset="article_posted,articles_deleted">
<!-- code -->
</txp:etc_cache>

But, since you have many articles, auto-updating will take some time.

Edit: that’s not a very good idea, though, because pg is set by site visitors. A bad guy bombarding your site with ...&pg=666 requests would quickly overfill the cache table. Probably, <txp:page_url type="pg" /> should be limited by some reasonable value.


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

Offline

#194 2017-03-20 08:52:47

alicson
Member
Registered: 2004-05-26
Posts: 465
Website

Re: etc_pagination: paginate everything

etc wrote #304922:

I think you need to create a cache block per page:
<txp:etc_cache id='archives-<txp:page_url type="pg" />' reset="article_posted,articles_deleted">...

That seems to have solved it, thank you!

But, since you have many articles, auto-updating will take some time.

Where/how will I notice the updating “taking time”?

…Probably, <txp:page_url type="pg" /> should be limited by some reasonable value.

Thank you very much for this too! I’ll set the limit in the etc_pagination tag, yes?


textpattern.org :: find and share Textpattern resources
docs.textpattern.io :: Textpattern user documentation

Offline

#195 2017-03-20 09:07:43

etc
Developer
Registered: 2010-11-11
Posts: 3,199
Website

Re: etc_pagination: paginate everything

alicson wrote #304925:

Where/how will I notice the updating “taking time”?

When you will publish a new article or delete an existing one. Set as above, etc_cache will try to update the cache for each page, and this can take time.

Thank you very much for this too! I’ll set the limit in the etc_pagination tag, yes?

You are already counting the articles with etc_query, right? Try to reuse the counter variable somehow. ;-)


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

Offline

#196 2017-03-20 09:26:34

alicson
Member
Registered: 2004-05-26
Posts: 465
Website

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

etc
Developer
Registered: 2010-11-11
Posts: 3,199
Website

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.


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

Offline

#198 2017-03-20 18:47:12

alicson
Member
Registered: 2004-05-26
Posts: 465
Website

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

etc
Developer
Registered: 2010-11-11
Posts: 3,199
Website

Re: etc_pagination: paginate everything

alicson wrote #304945:

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

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.


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

Offline

#200 2017-03-20 21:02:46

alicson
Member
Registered: 2004-05-26
Posts: 465
Website

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

Board footer

Powered by FluxBB