OpenBayou Posted January 17, 2017 Share Posted January 17, 2017 Hello, How do you do pages on a template? For example, I want my template to show only 5 posts. If there's more, do page=2. Search results I found results in errors on my end. // posts from the parent page. Only show 5 posts <?php foreach($pages->find("parent=recommendations,limit=5") as $child) { ?> <?php echo $child->title;?><br /> <?php } ?> Link to comment Share on other sites More sharing options...
flydev Posted January 17, 2017 Share Posted January 17, 2017 Hi OpenBayou, did you read this ? https://processwire.com/api/modules/markup-pager-nav/ 2 Link to comment Share on other sites More sharing options...
OpenBayou Posted January 17, 2017 Author Share Posted January 17, 2017 Got it working! Thanks! The results are: Quote 1 2 next Is there a way to remove the page numbers in-between next and prev? Link to comment Share on other sites More sharing options...
kongondo Posted January 17, 2017 Share Posted January 17, 2017 1 Link to comment Share on other sites More sharing options...
szabesz Posted January 17, 2017 Share Posted January 17, 2017 (edited) 1 hour ago, OpenBayou said: Is there a way to remove the page numbers in-between next and prev? Hi, is it the same question? If so, just read the topic. Edit: @kongondo beat me Edited January 17, 2017 by szabesz I was too slow to reply :) Link to comment Share on other sites More sharing options...
OpenBayou Posted January 17, 2017 Author Share Posted January 17, 2017 Is there anything easier? Link to comment Share on other sites More sharing options...
kongondo Posted January 17, 2017 Share Posted January 17, 2017 Did u see this as well? 1 Link to comment Share on other sites More sharing options...
szabesz Posted January 17, 2017 Share Posted January 17, 2017 6 minutes ago, OpenBayou said: Is there anything easier? Hiding them by CSS (display: none)? Link to comment Share on other sites More sharing options...
OpenBayou Posted January 17, 2017 Author Share Posted January 17, 2017 Just now, szabesz said: Hiding them by CSS (display: none)? It's not really good practice because it still loads the data and your browser is hiding it. Link to comment Share on other sites More sharing options...
OpenBayou Posted January 17, 2017 Author Share Posted January 17, 2017 4 minutes ago, kongondo said: Did u see this as well? I couldn't get it to work. When I got it to work it either shows the next post or array, not page2. Link to comment Share on other sites More sharing options...
szabesz Posted January 17, 2017 Share Posted January 17, 2017 Just now, OpenBayou said: It's not really good practice because it still loads the data and your browser is hiding it. Sure But this is the easiest Anyway, other options are in the thread we linked to. Link to comment Share on other sites More sharing options...
szabesz Posted January 17, 2017 Share Posted January 17, 2017 How about this? Link to comment Share on other sites More sharing options...
tpr Posted January 17, 2017 Share Posted January 17, 2017 41 minutes ago, OpenBayou said: It's not really good practice because it still loads the data and your browser is hiding it. I don't think you should worry about those extra characters in the markup. 1 Link to comment Share on other sites More sharing options...
OpenBayou Posted January 17, 2017 Author Share Posted January 17, 2017 Thanks everyone. Got it working but don't like how complex it is to do next page and previous page while other CMSs have an easy option. <?php $total_pages = ceil($pagedata->getTotal() / $limit);?> <?php if($total_pages > 1): $current_url = $page->url; if($input->urlSegmentsStr) $current_url .= $input->urlSegmentsStr . '/'; ?> <div class="pagination"> <?php if($input->pageNum > 2): ?> <div class="prev-page"> <a rel="prev" href="<?= $current_url . $config->pageNumUrlPrefix . ($input->pageNum - 1) ?>">Prev page</a> </div> <?php elseif($input->pageNum === 2): ?> <div class="prev-page"> <a rel="prev" href="<?= $current_url ?>">Prev page</a> </div> <?php else: ?> <?php endif; ?> <?php if($input->pageNum < $total_pages): ?> <div class="next-page"> <a rel="next" href="<?= $current_url . $config->pageNumUrlPrefix . ($input->pageNum + 1) ?>">Next page</a> </div> <?php else: ?> <?php endif; ?> </div> <?php endif; ?> 1 Link to comment Share on other sites More sharing options...
LostKobrakai Posted January 18, 2017 Share Posted January 18, 2017 It's as complex as building such things on your own elsewhere. We have an easy pagination generating module, which just happens to lack an option to render just next/prev links instead of a full pagination. I'm sure Ryan could add those quite easily. Also may I suggest a more readable version of yours. Things are always easier to digest when they're not muddled with html tags. <?php $next = $prev = ''; $total_pages = ceil($pagedata->getTotal() / $limit); if($input->pageNum > $total_pages) // Optional; For page 11 of 10 throw new Wire404Exception(); if($total_pages > 1){ $base_url = rtrim($page->url . $input->urlSegmentsStr, '/') . '/'; if($input->pageNum == 2) $prev = $base_url; elseif($input->pageNum > 2) $prev = $base_url . $config->pageNumUrlPrefix . ($input->pageNum - 1); if($input->pageNum < $total_pages) $next = $base_url . $config->pageNumUrlPrefix . ($input->pageNum + 1); } ?> <?php if($next || $prev) : ?> <div class="pagination"> <?php if($prev): ?> <div class="prev-page"> <a rel="prev" href="<?= $prev ?>">Prev page</a> </div> <?php endif; if($next): ?> <div class="next-page"> <a rel="next" href="<?= $next ?>">Next page</a> </div> <?php endif; ?> </div> <?php endif; ?> 3 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