Jump to content

Pager confusion


adrian
 Share

Recommended Posts

This is my second site using pagination. The first worked without a hitch.

Now, setting it up on various sections of a new site and all was seeming straight forward until I came across a couple of pages on the site (not all) that needed to have Allow Page Numbers turned on for the child template (the one the holds the items to be paginated) as well. If it's not on, then the links appear as ?page=n. These links don't work (they load the first page), and if you manually enter /page2 as the URL, it works fine.

The following lines in the module are what's relevant:

$allowPageNum = $this->options['page']->template->allowPageNum;

///////////////////

if($allowPageNum) {
	if($slashUrls === 0) $url .= '/'; // enforce a trailing slash, regardless of slashUrls template setting
		$url .= "$pageNumUrlPrefix{$item->pageNum}" . $this->queryString;
	} else {
		$url .= $this->queryString . ($this->queryString ? "&" : "?") . "$pageNumUrlPrefix=" . $item->pageNum;
				}

It doesn't really matter - I just allow page numbers in the child template too and everything works as expected, but curious why it is happening.

Anyone have any ideas?

Link to comment
Share on other sites

The following lines in the module are what's relevant:

What module? I'm thinking this is MarkupPagerNav, but want to double check. 

It doesn't really matter - I just allow page numbers in the child template too and everything works as expected, but curious why it is happening.

I can't think of any reason why you'd have to allow page numbers in the child page, unless you are doing some of your own page renders that themselves do pagination: $child->render(). Is your template calling render() on any other pages? Might be good to see the template code where the issue appears, as well as your code that outputs the pagination. 

Link to comment
Share on other sites

Yep, I am talking about the MarkupPagerNav module. I simplified my code down to something that still causes the issue to appear.

$results = $page->children('limit=10');$out .= $results->renderPager();
I have a few different sections on the site like:

training >training-items

teaching > teaching-items

publications > publication-item

These represent the parent and child pages and the template names. Some of them work without page number option being on in the child template and some don't.

The code is otherwise identical from what I can see.

Link to comment
Share on other sites

Actually I am curious about that if statement in the module to show the url with ?page=n if allowpagenum is off. What is the scenario where you would want that? Sorry if I am missing something obvious.

Link to comment
Share on other sites

Actually I am curious about that if statement in the module to show the url with ?page=n if allowpagenum is off. What is the scenario where you would want that?

You'd only want that if you were planning to set the page number yourself from it. ProcessWire doesn't recognize any GET variables in the core. The most valuable presence of that variable [for me] is as a flag that I need to turn on page numbers for the template. 

Is your template calling render(); on any other pages? Are you using URL segments? Are you setting any of the MarkupPagerNav options manually? What other modules are in the system? There are factors that could feasibly come into play, so I'd need to know everything that's happening in order to say for sure.  

Link to comment
Share on other sites

Hey Ryan,

The only render call in the template is for the pager. Not using URL segments. No manual pager options. 

I figured out the problem - I have a form on that page that allows a guest user to submit a new child page (unpublished of course). The form code was setting the page template to that of the child page, which was why

$allowPageNum = $this->options['page']->template->allowPageNum; 

was returning false.

Sorry for not figuring this out sooner!

  • Like 1
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

  • Recently Browsing   0 members

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