Jump to content

Buidling a PageArray for Pagination


Hari KT
 Share

Recommended Posts

Hi Guys,

I have a trouble with building PageArray.

Actually I am running the selector on a log when an article is read.

The template=history , with article field links to article template .

When a user reads an article I log to history the time article read. Think something similar to facebook history .

Now I am trying to get the history back. So what I am doing is

$articles_history = $pages->find("template=history, limit=3");
$articles = new PageArray();
$articles->setLimit($limit);
$articles->setTotal($articles_history->getTotal());
$start = ($input->pageNum - 1) * $limit;
$articles->setStart($start);
foreach ($articles_history as $article_history) {
   $articles->add($article_history->article);
}

$pagination = $articles->renderPager(array(
    'currentItemClass' => 'active',
    'listMarkup' => "<ul class='pagination'>{out}</ul>",
    'itemMarkup' => "<li class='{class}'>{out}</li>",
    'linkMarkup' => "<a href='{url}'><span>{out}</span></a>",
    'separatorItemLabel' => "<span>…</span>"
));
echo $pagination;

There are a few troubles though when the article is same. The PageArray will add only once, and no more duplicates are added. That is one trouble.

Now the actual trouble is the correct pagination is not coming. I wonder whether it is due to this reason.

There is only total 10 articles with 2 being duplicates. I added a limit of 3. Then the pagination on first shows me 1, 2, 3, 4, 5. Not sure why though.

Is there a way to fix this ? If you have thought of using the $articles_history then I could not because the templates are required :-/ and being used by other places. Something like partials.

Thank you

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

×
×
  • Create New...