Jon Posted October 24, 2019 Share Posted October 24, 2019 Hello All, Iam having a slight problem with pagination, Ive setup a news page with pagination which works fine. I have also setup a segment that list all the posts for a set year using the same template. for example news/2018 when I try and display page2 I get a 404 any idea? The code Ive used. <?php if ($input->urlSegment1) { $start = strtotime(date("{$input->urlSegment1}-01-01")); $end = strtotime(date("{$input->urlSegment1}-12-31")); $results = $pages->find("template=news-item|news-item-right-gallery|news-item-left-gallery, news_date>=$start, news_date<=$end, limit=15, sort=-news_date"); }else{ $results = $pages->find("template=news-item|news-item-right-gallery|news-item-left-gallery, limit=15, sort=-news_date"); } foreach($results as $result) {?> News template <?php } $pagination = $results->renderPager(); echo $pagination; ?> Cheers Jon Link to comment Share on other sites More sharing options...
JayGee Posted October 25, 2019 Share Posted October 25, 2019 I think it could be because you are also using url segments. You can set the base URL for the page to be paginated when calling the pager. I can't seem to find the relevant docs at the moment but this is a snippet from a project I have open at the moment that I recall has the same issue that hopefully shows the syntax you need. $pagination = $articles->renderPager(array( 'baseUrl' => '/sector/'.$currentCat.'/' )); Link to comment Share on other sites More sharing options...
gmclelland Posted October 25, 2019 Share Posted October 25, 2019 What is the url for page2? Link to comment Share on other sites More sharing options...
gmclelland Posted October 25, 2019 Share Posted October 25, 2019 If a url segment for year exist, you might have to whitelist the year? https://processwire.com/api/ref/wire-input/whitelist/ Link to comment Share on other sites More sharing options...
Jon Posted October 25, 2019 Author Share Posted October 25, 2019 8 hours ago, Guy Incognito said: I think it could be because you are also using url segments. You can set the base URL for the page to be paginated when calling the pager. I can't seem to find the relevant docs at the moment but this is a snippet from a project I have open at the moment that I recall has the same issue that hopefully shows the syntax you need. $pagination = $articles->renderPager(array( 'baseUrl' => '/sector/'.$currentCat.'/' )); I tried this and get the same results 2 hours ago, gmclelland said: What is the url for page2? domain.com/news/2018/page2 Just reading up on whitelist now. Link to comment Share on other sites More sharing options...
JayGee Posted October 26, 2019 Share Posted October 26, 2019 Just to double check - did you enable page numbers in the page template settings? Link to comment Share on other sites More sharing options...
Jon Posted October 26, 2019 Author Share Posted October 26, 2019 3 minutes ago, Guy Incognito said: Just to double check - did you enable page numbers in the page template settings? Yes just double checked and that's enabled /news pagination work just if the year is used. Tried whitelisting the variable but getting the same results 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