Jump to content
Jon

Pagination issue with urlSegment2

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

Share this post


Link to post
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.'/'
                ));

 

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...