Jump to content

Pager Render works but the query of pages isn't


Pip
 Share

Recommended Posts

Hi all, 

Using the Pager to do some pagination. The render seems to work nicely - render meaning to print 1, 2, 3, next. 

But upon clicking the links, the page does redirect but the results is as good as clicking on the # link. 

Results are not moving to the next set. Noted that it happens that it behaves nicely but most of the time the results won't move. 

Any idea where I went wrong? 

<h1><?php echo $page->title; ?></h1>
		<?php if($page->editable()) echo "<p><a href='$page->editURL'>Edit</a></p>"; ?>
		<?php echo $page->body; ?>
			
		<?php 
			// Declare variables
			$newcolors = array() ; 
			$confabulations = $pages->find("start=0, id>1018, template=confabulation, sort=-id, limit=5"); 
			foreach ($confabulations as $i) {
				..... Some design work and output ... 
			}
	
		?>
			<div class="pagination"><?php echo $confabulations->renderPager();?> </div>

Added start=0 into the selector but nothing seems to happen. 

Help

Link to comment
Share on other sites

You need to remove the start=0 from your selector. Automatic pagination works by automatically injecting the start parameter into all pages queries with a limit, based on the defined limit and the current page number. By including a start selector you overwrite this behaviour, forcing ProcessWire to not return paginated results for that query. See Pagination in ProcessWire, section "Are there any side effects?"

If it isn't working without the start selector either, and it's just not working sometimes, it might just be a caching issue.

Link to comment
Share on other sites

@MoritzLost Thanks for the reply! Yeah that did the job! It's weird really could have sworn it was without the start=0 previously and it didn't work. 

Will keep a close eye on this because I've been getting some weird behaviors. 

Thanks!

  • Like 1
Link to comment
Share on other sites

Ugh. So much for short lived happiness. Suggested the edits you recommended @MoritzLost and suddenly tada.... 

?

It work for a short time only and then tada we're back. You reckon that pagination only works for one template only? Because I'm using it in two different templates. 

My codes as of now: 

 

 

Link to comment
Share on other sites

  <?php
  $newcolors = array();
  $confabulations = $pages->find( "template=confabulation, limit=5, sort=-id" );
  ?>
  <div class="pagination"><?php echo $confabulations->renderPager();?>
    <div style="clear:both;"></div>
  </div>
  <?php
  foreach ( $confabulations as $i ) {
    $newid = intval( $i->id ) - $basepageid;
    $newcolors = genColor();
    // $newcolors [0] = background 
    // $newcolors [1] = flap 
    // $newcolors [2] = text


    echo "<div class=\"post " . $newcolors[ 2 ] . "\" style=\"background-color:#" . $newcolors[ 0 ] . ";\">"
    . "<a href=\"" . $i->url . "\"><div class=\"flap\" style=\"background-color: #" . $newcolors[ 1 ] . "; color: #" . $newcolors[ 0 ] . "\">"
    . $newid . "</div></a>"
    . "<h2>" . $i->title . "</h2>" . $i->confabulation_body . "<div class=\"author\">" . $i->confabulation_pseudonym . "</div>
						<div style=\"clear:both;\"></div></div>";
  }


  ?>
  <div class="pagination"><?php echo $confabulations->renderPager();?>
    <div style="clear:both;"></div>
  </div>

 

Link to comment
Share on other sites

@Pip Hm, the code looks good to me. Have you made sure that the pagination option is active in both templates you need it in? Other than that ... maybe calling renderPager() twice is tripping something up? Maybe save the result in a variable and output that instead. Also, you sort by ID? That's curious, are you relying on newer pages having higher IDs? In this case, maybe just sort by created date (sort=-created). And again, have you made sure there's no caching active on any layers?

Link to comment
Share on other sites

On 8/8/2020 at 9:41 PM, MoritzLost said:

Have you made sure that the pagination option is active in both templates you need it in?

Confirmed. 

 

On 8/8/2020 at 9:41 PM, MoritzLost said:

Other than that ... maybe calling renderPager() twice is tripping something up? Maybe save the result in a variable and output that instead.

You're talking about the $pages->find? 

On 8/8/2020 at 9:41 PM, MoritzLost said:

And again, have you made sure there's no caching active on any layers?

Sorry kinda lost on this. Though I made sure by clearing the cache also forcing the refresh Ctrl+Shift+r

Link to comment
Share on other sites

2 minutes ago, Pip said:

You're talking about the $pages->find? 

Did a simple var_dump. Well for the correct template, it does change. But for the wrong one the values still remain the same. 

It's like the pointer never moves. ?

Link to comment
Share on other sites

@MoritzLost You know by default the home template includes the "basic-page"? 

I changed it to the confabulations page. Thing is, I was checking on the actual Home page for the pagination. 

Apparently, even though if you enabled pagination the included page, it's the page's main template that pagination should be enabled. ?

Link to comment
Share on other sites

Alright, I see. Though this makes sense, even if you include a different PHP template, you're still viewing a template of type "home", and ProcessWire uses the settings of this template to determine stuff like pagination, url segments, caching etc. For the record, this is what I meant by Have you made sure that the pagination option is active in both templates you need it in? ?

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