OllieMackJames Posted December 19, 2013 Share Posted December 19, 2013 I want to use pagination together with infinitescroll This means I need to output only the nextitem link on the bottom of each paginated page, Currently the pagination module outputs the following: - on the first paginated page it shows: 1 2 3 next - on the scond paginated page it shows: prev 1 2 3 next - on the last it shows: prev 1 2 3 And I want it to show this: - first paginated page: next - second paginated page: next - last paginated page: you have reached the bottom, thanks for checking this far! Infinitescroll.js looks in the page for the next link and calls the next pages results and appends them to the current page, like pinterest and facebook are doing. Hope this makes sense so far. So, what I need is ONLY the next link and that then also formatted in a specific way so infinitescroll recognises it and knows to load the next paginated page Here is my current code: <?php $results = $pages->find("template=blogpost-iframe, limit=10"); $pagination = $results->renderPager(array( 'nextItemLabel' => "Next", 'nextItemClass' => "jscroll-next", )); foreach($results as $result) { $imgURL = $result->images->first()->url; // original image $thumbWidth = 192; $thumbWidthPX = $thumbWidth . 'px'; $thumb = $result->images->first()->size($thumbWidth); $thumbURL = $thumb->url; $siteURL = $pages->get(1)->httpUrl; // home URL $summary = $result->summary; $title = $result->title; $blogURL = $result->httpUrl; $frontSummary = $result->frontSummary; echo <<<BLOGEOF <div class="tack"> <div class="tackHolder"> <div class="actions"> <div class="left"> <a class="button" href="http://pinterest.com/pin/create/button/?url=$siteURL/&media=$imgURL&description=$summary"><strong><em></em>Repin</strong></a> </div> <div class="left"> <div id="facebook_like_button_holder" > <a title="send to Facebook" href="http://www.facebook.com/sharer.php?s=100&p[title]=$title&p[summary]=$summary&p[url]=$blogURL&p[images][0]=$imgURL" target="_blank"><div id="fake_facebook_button" class="button"><strong><em></em>like</strong></div></a> </div> </div> </div> <a href="$blogURL" class="iframe cboxElement" title="$title"><img src="$thumbURL" alt="$title" title="$title" class="tack_img drthumbonly" width="$thumbWidthPX"/></a> </div> $frontSummary <p class="links"><a href="$blogURL" class="iframe cboxElement">Meer Informatie...</a></p> </div> BLOGEOF; } echo $pagination; ?> The aboe outputs the first 10 results and then also: <ul class='MarkupPagerNav'> <li class='MarkupPagerNavOn MarkupPagerNavFirst MarkupPagerNavFirstNum'><a href='/pw/'><span>1</span></a></li> <li><a href='/pw/seite2'><span>2</span></a></li> <li class='MarkupPagerNavLastNum'><a href='/pw/seite3'><span>3</span></a></li> <li class='jscroll-next MarkupPagerNavLast'><a href='/pw/seite2'><span>Next</span></a></li> </ul> It should only output: <class='jscroll-next'><a href='/pw/seite2'><span>Next</span></a> or something like that Help much appreciated! Link to comment Share on other sites More sharing options...
leoric Posted December 20, 2013 Share Posted December 20, 2013 http://processwire.com/api/variables/page/ you can use : $page->next / $page->prev try this: <?php if($page->next->id){ echo "<class='jscroll-next'><a href='{$page->next->path}'><span>Next</span></a>"; } ?> Link to comment Share on other sites More sharing options...
OllieMackJames Posted December 20, 2013 Author Share Posted December 20, 2013 On 12/20/2013 at 2:40 AM, leoric said: http://processwire.com/api/variables/page/ you can use : $page->next / $page->prev try this: <?php if($page->next->id){ echo "<class='jscroll-next'><a href='{$page->next->path}'><span>Next</span></a>"; } ?> @leoric, Thanks for thinking along, tried that but that does not work like it should. seems to me that the $page->next->id etc code is part of the core of regular pw, my question focuses on code that works with the pagination core module, and the page->next takes something from the tree, it takes the next sibling, but with pagination there is no real sibling, but only an automatic split up of a page. Par example I might have 50 results to the call: $results = $pages->find("template=blogpost-iframe, limit=10"); Then the pagination module kicks in and paginates the results into 5 pages with each 10 results, so it adds 'virtual' pages that can only be found and called by the paginationmodule, so that is why your code does not work here I believe. I might understand it wrong, but this is how I think it works, I therefore need focused input on how to work 'under the hood' of the pagination module. But once again, thanks for thinking along, it helps me figure it out better and hopefully point others to the right direction where to seek the answer. Link to comment Share on other sites More sharing options...
Soma Posted December 20, 2013 Share Posted December 20, 2013 You might want to look into that thread http://processwire.com/talk/topic/5145-paginator-and-seo/ Link to comment Share on other sites More sharing options...
OllieMackJames Posted December 20, 2013 Author Share Posted December 20, 2013 On 12/20/2013 at 8:45 AM, Soma said: You might want to look into that thread http://processwire.com/talk/topic/5145-paginator-and-seo/ Thanks soma, I take it you mean this code: $pageNum = $input->get->page ? $input->get->page - 1 : 0; $limit = 5; $start = $pageNum * $limit; $result = $page->children("start=$start, limit=$limit"); echo $result->renderPager(); foreach($result as $p) echo "<p>$p->url</p>"; echo $result->renderPager(); I tried that as well and that first gives me - the paginated pages - it seems to add one page extra to the end of the paginated pages with an overisight of next paginated pages plus 5 more pages in the pw tree - then it shows the paginated pages again So this also sends me in a direction that shows more of what pw can do when someone who understands coding has a go at it, but I have to admit I am pretty much clueless with code, and all I can do is copy paste. But I think I understand what I want pretty clear and that is paginate a list of results and only show the next link at the bottom of any of the paginated pages, excluding the last paginated page of course, since that one shows the bottom of the results. I have changed the first post of this thread because judging by the reactions of others I have done a poor job of explaining what I would like, my bad, so let me try to correct that here as well: OK here goes: currently the pagination module outputs the following: - on the first paginated page it shows: 1 2 3 next - on the second paginated page it shows: prev 1 2 3 next - on the last it shows: prev 1 2 3 And I want it to show this: - first paginated page: next - second paginated page: next - last paginated page: you have reached the bottom, thanks for checking this far! Infinitescroll.js looks in the page for the next link and then uses this next link to read the output of the next paginated page and appends it to the current page, that will give me the efect that is used on pinterest and also on facebook where once you scroll down it just keeps adding to the current page. Thanks again, I hope someone can point me to the solution, I have now downloaded the pagination module and am looking in the source there to figure out how to just get it to show the next link only. Link to comment Share on other sites More sharing options...
Martijn Geerts Posted December 20, 2013 Share Posted December 20, 2013 Do you have somewhere else a search on the page for the same pages ? If thats true, try to add start=0 to the other find calls. Link to comment Share on other sites More sharing options...
Soma Posted December 20, 2013 Share Posted December 20, 2013 No I mean the code for prev next by teppo, not the one I wrote cause that's different thing. if ($input->pageNum) { $limit = 15; // whatever limit you're actually using if ($input->pageNum > 1) { echo "<link rel='prev' href='{$page->url}{$config->pageNumUrlPrefix}".($input->pageNum-1)."' />"; } if ($input->pageNum * $limit < $items->getTotal()) { echo "<link rel='next' href='{$page->url}{$config->pageNumUrlPrefix}".($input->pageNum+1)."' />"; } } Or $limit = 12; // the "limit"-setting used on this page $children = $page->children("limit=" . $limit); $totalpages = ceil($children->getTotal() / $limit); // PAGINATOR: set SEO tags for Google if ($input->pageNum) { if ($input->pageNum < $totalpages) { echo "<link rel='next' href='" . $page->url . $config->pageNumUrlPrefix . ($input->pageNum + 1) . "' />"; } if ($input->pageNum > 1) { echo "<link rel='prev' href='" . $page->url . $config->pageNumUrlPrefix . ($input->pageNum - 1) . "' />"; } } I don't think modifiying the pager module is good or easy, as you're saying your not a coder even less. And pager module doesn't allow to do what you need. But with some custom code in template you can more easily generate a next link based on the pageNum etc. Maybe someone can help you getting the logic from the above script to what you exactly need. 3 Link to comment Share on other sites More sharing options...
OllieMackJames Posted December 20, 2013 Author Share Posted December 20, 2013 On 12/20/2013 at 9:25 AM, Martijn Geerts said: Do you have somewhere else a search on the page for the same pages ? If thats true, try to add start=0 to the other find calls. Thanks Martijn, added that to the following code: $results = $pages->find("template=blogpost-iframe, limit=10, start=0"); and that did not change anything, so I guess that is not what I need then. On 12/20/2013 at 9:30 AM, Soma said: No I mean the code for prev next by teppo, not the one I wrote cause that's different thing. if ($input->pageNum) { $limit = 15; // whatever limit you're actually using if ($input->pageNum > 1) { echo "<link rel='prev' href='{$page->url}{$config->pageNumUrlPrefix}".($input->pageNum-1)."' />"; } if ($input->pageNum * $limit < $items->getTotal()) { echo "<link rel='next' href='{$page->url}{$config->pageNumUrlPrefix}".($input->pageNum+1)."' />"; } } Or $limit = 12; // the "limit"-setting used on this page $children = $page->children("limit=" . $limit); $totalpages = ceil($children->getTotal() / $limit); // PAGINATOR: set SEO tags for Google if ($input->pageNum) { if ($input->pageNum < $totalpages) { echo "<link rel='next' href='" . $page->url . $config->pageNumUrlPrefix . ($input->pageNum + 1) . "' />"; } if ($input->pageNum > 1) { echo "<link rel='prev' href='" . $page->url . $config->pageNumUrlPrefix . ($input->pageNum - 1) . "' />"; } } I don't think modifiying the pager module is good or easy, as you're saying your not a coder even less. And pager module doesn't allow to do what you need. But with some custom code in template you can more easily generate a next link based on the pageNum etc. Maybe someone can help you getting the logic from the above script to what you exactly need. Thanks soma, the first option threw an error about an object not being there, the second option is definitely a step forward, now I get this result in my source: <link href="/pw/seite2" rel="next"> so the question now is how to get this line: echo "<link rel='next' href='" . $page->url . $config->pageNumUrlPrefix . ($input->pageNum + 1) . "' />"; to output: <a href="/pw/seite2 rel="next">Next</a> Thnks all for thinking along, much appreciated! Link to comment Share on other sites More sharing options...
OllieMackJames Posted December 20, 2013 Author Share Posted December 20, 2013 Ok got it this gives me the next link, mind you I still had to turn on pagination on the template but here is the code that gives me the next link: <?php $limit = 5; // the "limit"-setting used on this page $children = $page->children("limit=" . $limit); $totalpages = ceil($children->getTotal() / $limit); // PAGINATOR: set SEO tags for Google if ($input->pageNum) { if ($input->pageNum < $totalpages) { echo "<a rel='next' href='" . $page->url . $config->pageNumUrlPrefix . ($input->pageNum + 1) . "'>Next "; } } ?> Question remains how to get the last page to say: Thanks, you have reached the bottom now. Link to comment Share on other sites More sharing options...
OllieMackJames Posted December 20, 2013 Author Share Posted December 20, 2013 OK BIG thanks to soma, who helped me get this, here is the final one: <?php $limit = 5; // the "limit"-setting used on this page $children = $page->children("limit=" . $limit); $totalpages = ceil($children->getTotal() / $limit); // PAGINATOR: set SEO tags for Google if ($input->pageNum) { if ($input->pageNum < $totalpages) { echo "<a rel='next' href='" . $page->url . $config->pageNumUrlPrefix . ($input->pageNum + 1) . "'>Next "; } else { echo "Thanks for browsing, you have reached the bottom of this page!"; } } ?> Once again, thanks to all for thinking along, now the next hurdle, to get infinitescroll to do the rest! 6 Link to comment Share on other sites More sharing options...
adrianmak Posted February 23, 2015 Share Posted February 23, 2015 How could I do pagination thru ajax ? Link to comment Share on other sites More sharing options...
LostKobrakai Posted February 23, 2015 Share Posted February 23, 2015 You could either use a dedicated tempate for this page, enable pagination for it and let you javascript call the sites: e. g. /search/page{1, …}/. Then just use the pagination like everywhere else. Or you do implement the pagination calculation yourself, so you don't need to change the url. I don't have the details in mind, so maybe you need to adjust the numbers to fit the difference of counting from 0 or from 1 and you should check it the page even exists. See the example above for more on that. $limit = 5; $start = $limit * $input->post->pageNum; //get this from the ajax call $paginatedPages = $pages->find("your=selectors, limit=$limit, start=$start"); 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