Jump to content

Pagination issue with urlSegment2


Jon
 Share

Recommended Posts

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

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

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...