Jump to content

Pages find strange behaviour [pw 2.6.1]


Recommended Posts

Posted

Hello for all,

Please before read, just one note here - in problem description I use word "article" for child pages.

I have category "News" with about 700 articles.

Because on every News page are list with 5 articles, pagination goes from 1 to 141 pages.

On sidebar I render "widget" where are 3 articles from another category ("Projects").

Projects articles: a, b, c, d, e, f, g, h, i, j, k...

Problem:

News page 1, widget Project shows: a, b, c - correct

News page 2, widget Project shows: d, e, f - wrong (need to show a, b, c)

News page 3, widget Project shows: g, h, i - wrong (need to show a, b, c)

And same principle on other pages...

Widget render articles using $pages->find call:

$items = $pages->find("parent={$page->parent_page->id}, limit={$page->num_of_articles}, sort=-date_end");

Any help?

Thanks.

Posted

You're using limit in both selectors and pagination does set the start value automatically, if there's non present. That's why both finds do get paginated. Add start=0 to the widget selector and it works.

  • Like 2
Posted

Thanks LostKobrakai!

There is still too many PW secrets for me, read almost all documentation but couldn't find this what you write here.

I will remember this:

Pagination can make "troubles" because it can be in correlation with other MySQL queries ($pages->find) on the same page.

Thank you!

EDIT 27.09.2015:

Thanks @SiNNuT I find where Ryan write about this (Avoiding pagination pitfalls, 25.09.2015.): 

If you have other find() operations with "limit=n" selectors occurring elsewhere during that same request, ProcessWire will try to paginate them too. That may not be what you want.

Posted

The starting result is always the first, unless you use the "start" reserved word, i.e. start=50, limit=50

If you are using a limit selector with pages, and your template has page-numbers turned on, ProcessWire will automatically set the "start" selector according to the current page number. So when it comes to pagination, you don't usually have to think about anything other than the "limit" selector.

See here: http://processwire.com/api/selectors/#limit

  • Like 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...