Pip Posted August 6, 2020 Share Posted August 6, 2020 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 More sharing options...
elabx Posted August 6, 2020 Share Posted August 6, 2020 Check to have pagination enabled in the template where your are rendering the pager. https://processwire.com/docs/front-end/markup-pager-nav/ Link to comment Share on other sites More sharing options...
Pip Posted August 7, 2020 Author Share Posted August 7, 2020 13 hours ago, elabx said: Check to have pagination enabled in the template where your are rendering the pager. https://processwire.com/docs/front-end/markup-pager-nav/ Hi @elabx! Previously it was working. Dunno why lately it decided to well not work. But here's a screenshot of the template: Link to comment Share on other sites More sharing options...
MoritzLost Posted August 7, 2020 Share Posted August 7, 2020 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 More sharing options...
Pip Posted August 7, 2020 Author Share Posted August 7, 2020 @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! 1 Link to comment Share on other sites More sharing options...
Pip Posted August 7, 2020 Author Share Posted August 7, 2020 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 More sharing options...
Pip Posted August 7, 2020 Author Share Posted August 7, 2020 <?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 More sharing options...
MoritzLost Posted August 8, 2020 Share Posted August 8, 2020 @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 More sharing options...
Pip Posted August 12, 2020 Author Share Posted August 12, 2020 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 More sharing options...
Pip Posted August 12, 2020 Author Share Posted August 12, 2020 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 More sharing options...
Pip Posted August 12, 2020 Author Share Posted August 12, 2020 Found it. Omg. So it's because my Home per se is not allowed to do pagination. Despite my home includes the confabulation template. D'oh! Link to comment Share on other sites More sharing options...
MoritzLost Posted August 13, 2020 Share Posted August 13, 2020 @Pip Glad you found the cause of the issue, but could you clarify what you mean by your home is not allowed to do pagination? Is the option not active in the template? Link to comment Share on other sites More sharing options...
Pip Posted August 13, 2020 Author Share Posted August 13, 2020 @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 More sharing options...
MoritzLost Posted August 13, 2020 Share Posted August 13, 2020 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 More sharing options...
Pip Posted August 13, 2020 Author Share Posted August 13, 2020 @MoritzLost No more doing codes past 3am for me that's for sure. hahaha. Thanks, Moritz. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now