verdeandrea Posted June 9, 2016 Share Posted June 9, 2016 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 More sharing options...
LostKobrakai Posted June 9, 2016 Share Posted June 9, 2016 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; } 2 Link to comment Share on other sites More sharing options...
kixe Posted June 10, 2016 Share Posted June 10, 2016 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); 3 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