Jump to content

Recommended Posts

Posted

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

Posted

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
Posted

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

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
  • Recently Browsing   0 members

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