Jump to content

Possible buggy url Segments / Page Numbers Interaction


tiagoroldao
 Share

Recommended Posts

It's possible that I'm missing something, but I think I have found an small bug.

I am doing a simple page list template (/photos) that is paginated and has url segments on, to allow for filtering through tags. As there are multiple different lists, and they all share the same tags, I need to list the tags that are relevant to this particular list (i.e. the tags that are in any of the list's pages). 

I attempted:

foreach ($pages->get("/tags")->children() as $key => $tag) {
  if($pages->count("parent=$page, tags=$tag") > 0){
    echo "<li><a href='$page->url$tag->name' $active>$tag->title</a></li>";
  }
}

And it seemed to work... BUT it broke on my final page (on page 3 of a 3 page pagination). After doing some testing, I found that this selector, when using pagination, correctly counts all the pages that have the given tag, only if there is at least one in the current page.

So:

  • If tag A is in 10 pages, and in the current pagination segment there are any of them, the selector returns 10, as expected
  • If tag B is in another 10 pages, but none of them are in the current pagination segment, the selector returns 0.
  • If I change the selector to address all pages, removing the parent selector, the problem goes away but:
    • Any parent selector pointing to the current parent (being paginated) break this, be it $page, $page->id, or the url or id entered manually
  • The problem occurs without any url segments actually being used. Haven't tested thoroughly enough to be able to tell if it has the same behaviour with url Segments set (i.e. on a tag-filtered subselection of the pages)
  • This was using a page field with multiple pages (as it was for tags)

I solved the problem using:

foreach ($pages->get("/tags")->children() as $key => $tag) {
  if($pages->find("parent=$page, tags=$tag")->count() > 0){
    echo "<li><a href='$page->url$tag->name' $active>$tag->title</a></li>";
  }
} 

Which works well. I can only think of this as a bug, but I may be missing something.

Link to comment
Share on other sites

You could also do this:

foreach ($pages->get("/tags")->children() as $key => $tag) {
    if ($pages->find("parent=$page, tags=$tag")->getTotal() > 0) {
        echo "<ul>";
        foreach ($pages->find("parent=$page, tags=$tag") as $tagpage){
            echo "<li><a href='$tagpage->url$tag->name' $active>$tag->title</a></li>";
        }
        echo "</ul>";
    }
}

I just threw in the wrapping UL elements, but if you want to paginate the results it needs some more work anyway :)

Link to comment
Share on other sites

Thanks for the reply  :rolleyes: I've simplified the markup for illustration purposes, yeah :P

There is a difference between $pageArray->count() and $pages->count("selector") - for my purposes, $pageArray->count() and $pageArray->getTotal() are functionally the same, and they both work. The issue is with $pages->count("selector"), that works as a getTotal() call, without the need to actually return the array of pages (and thus, getting less overhead). But it seems to bug out in this instance.

Link to comment
Share on other sites

:rolleyes: Yes, I solved it with:

$pages->find("parent=$page, tags=$tag, limit=1, start=0")->count()

The "start=0" was just to make sure it went well, as PW 2.3, as far as I know, doesn't paginate queries with limit=1.

I don't think that's it. But I may be looking at it wrong:

Shouldn't $pages->count() not be paginated?

And I find it strange that this scenario occurs: If I have 100 pages spread out across 10 pages, 50 "a's" and 50 "b's", and do a $pages->count("parent=theParentOfThe100Pages, tags=a") in one of the 10 pagination pages, if there is at least one "a" page, the $pages->count() returns 50, but if there is no "a" page in this particular set of 10, $pages->count() returns 0.

One extra question:

If all queries are paginated, imagining I'm in /page10 of the pagination, showing pages 91~100 of my list. If I were to do a $pages->find() on an unrelated group of pages, using the same limit=10, but on a group of pages with 50 pages (effectively having 5 pages of results), what would happen? would the result be an empty array, from page6 onward?

Link to comment
Share on other sites

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
 Share

×
×
  • Create New...