Jump to content

Link to specific page in archive with pagination


verdeandrea
 Share

Recommended Posts

Hi guys,

i have a news archive, where i cycle through a lot of pages and this cycle is paginated.

In my home page i need to link to a specific news, but not directly to its page, but to the archive page containing this news.

So if, for example, i have e news in page 3 of my archive, i would like to link to this page.

The question is, what is the best way to get the link to the right page of my archive?

Thank you

Link to comment
Share on other sites

I'm not sure if there's really a better way to do this, without potential for breakage.

$pageNum = 1;
$limit = 20;
$start = $pageNum - 1 * $limit;
$base = "template=news, id=$mySearchedPage->id";

while($pages->count($base . ", start=$start")){
  $count = $pages->count($base . ", limit=$limit, start=$start");
  if($count) break;
  $pageNum++;
  $start = $pageNum - 1 * $limit;
}
  • Like 2
Link to comment
Share on other sites

Another solution

// number of news per news page
$limit = 20;

// get all news
$allNews = $pages->find("template=news");

// get the specific news item
$selector =  // selectorstring to get specific news item
$specificNews = $allNews->get($selector);

// get the page number where to find the specific news item
$key = $allNews->getItemKey($specificNews);
$pageNum = ceil($key/ $limit);
  • Like 3
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...