Adam Kiss Posted September 18, 2011 Share Posted September 18, 2011 If you have set your template to use page numbers, system automatically accepts any 'page%d' url segment. This however means, that for every number greater then actual page count, empty page is rendered (or else, depending on your html/css). Instead system should either *return information about missing page* to let page administrator handle this, or simply *return 404* and let the system's 404 page inform the user. Or combination of both, so webdesigners can use 404, but handle this situation different way, if they want. Also, github issue was posted here: https://github.com/ryancramerdesign/P21/issues/52 Link to comment Share on other sites More sharing options...
ryan Posted September 18, 2011 Share Posted September 18, 2011 PW doesn't handle page numbers internally. Like with regular URL segments, it's up to you to decide what to do with them. PW doesn't know or care what your bounds are for page numbers. The MarkupPagerNav module is not a dependency for handling page numbers, and may or may not be used (that's a runtime decision). So if you want to handle numbers that are out of bounds, you can throw a Wire404Exception when that occurs (like you would with an unknown URL segment), though I don't usually bother with it. I think a better thing to do is to leave no results (with the pagination intact) or send a session->redirect back to page 1 or the last page. That way, if there used to be a page number in bounds that no longer is, at least you are providing a way for for that traffic to get back in-bounds. Link to comment Share on other sites More sharing options...
Adam Kiss Posted September 18, 2011 Author Share Posted September 18, 2011 I understand that, but I think there is difference between url segments and pagination here: Url Segments basically allow you to use url segments, but the only thing you get when turning it on, is access to 'child' URLs, and way to handle them. Whole logic about what to do with this is up to you, and so are any exceptions needed Pagination (or page numbers), on the other hand give you everything automated; you add one limit to your code, and that's it Because of this automation, I believe PW should either solve non-existent page URLs for you, or at least provide some simple method to detect it, something like $paginator->outOfBoundsPage(), or something like that. Link to comment Share on other sites More sharing options...
ryan Posted September 18, 2011 Share Posted September 18, 2011 Okay I see what you mean and think that makes sense. Though I still don't want the core taking any actions on this, as I just don't think there's any way for the core to know the developers intentions here. But I have no problem coding options into the MarkupPagerNav module. It does make for a more complex API, but it's also one of those things that's optional so not concerned about adding it. I'm thinking the options should be: MarkupPagerNav::outOfBoundsNone = 0; MarkupPagerNav::outOfBounds404 = 1; MarkupPagerNav::outOfBoundsRedirectFirst = 2; MarkupPagerNav::outOfBoundsRedirectLast = 3; Example: <?php $matches = $pages->find("..."); $pager = $matches->renderPager(array('outOfBounds' => MarkupPagerNav::outOfBounds404)); if(count($matches)) { echo $matches->render(); // or however you want to output echo $pager; // note $pager has to be generated before output since it may send 404 or redirect headers. } else { echo "<p>Sorry no matches</p>"; } Until we have such options, here is how you are supposed to do it now: <?php $matches = $pages->find("..."); if(count($matches)) { echo $matches->render(); // or however you want to output echo $matches->renderPager(); } else { if($input->pageNum > 1) throw new Wire404Exception(); echo "<p>Sorry no matches.</p>"; } Or if you are lazy like me and don't care too much about out of bounds: <?php $matches = $pages->find("..."); echo $matches->render() . $matches->renderPager(); if(!count($matches)) echo "<p>Sorry no matches.</p>"; Link to comment Share on other sites More sharing options...
apeisa Posted September 18, 2011 Share Posted September 18, 2011 Isn't it very rare to end up to page like example.com/news/page6/ if there isn't any results? If you use MarkupPager then it doesn't output any links like that. Of course if someone links there outside of the current site and it might have less content (or developer shows more items per page) now than it used to have at the time link was created - then this could occur. Or am I missing something very obvious? Link to comment Share on other sites More sharing options...
Adam Kiss Posted September 18, 2011 Author Share Posted September 18, 2011 Yep Also, I moved to PW from WP right now, and also shuffled categories a little bit – and since I split 6 categories into 12, some redirects go to empty pages now. Not that I care that much, but it got me with surprise – especially with all that auto-magic that happens when we do pagination with PW. Link to comment Share on other sites More sharing options...
apeisa Posted September 18, 2011 Share Posted September 18, 2011 Ah yes, that makes sense. Just a sidenote: it's not optimal to use pageN links on pages which get linked a lot (probably not a problem in most listings, but in some it might be), since content changes on page2 all the time (if you sort them by date and new ones first). So better option would be urls like /2010/08/ etc. if those make sense considering the content. Of course, also more work for the developer But probably most blogs work with normal pagination (page2, page3 etc) and those more permanent links are in archive section or something. Link to comment Share on other sites More sharing options...
Adam Kiss Posted September 18, 2011 Author Share Posted September 18, 2011 This is kind of like twice a year updated alcohol shop [posted in showcase now], so it's ok, I think 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