Jump to content

Pagination issue with three different queries on one template


a-ok
 Share

Recommended Posts

Hi folks,

I am using pagination on a news overview on my site. I have three queries set up on this page; a display first post, a display the next six (excluding the first) and then everything else (so excluding the first and the next six); so in theory the part I want to paginate starts at post 7 onwards. The only issue I have is when I click to the next page (page2) it shows the first post, the next six, then everything else, again.

I understand why this is happening... it is using the same template for page2, page3 etc etc, which includes those queries. Below is my entire setup. Is there any way around this? I've tried using 'start' positions etc but doesn't seem to work properly.

http://snippi.com/s/4ze4c4u (this is my entire setup for the news page)

Any help or ideas? Many thanks.

Link to comment
Share on other sites

well you have some fairly nested stuff going on in there, it's tough to read/parse;

i think what you'd need to do is setup your standard pagination and give it the necessary details...

you may need to remove the first 7 items from this page array and do what you want with those, so that the start is with post 7

this is just a generic snippet showing what i usually do on paginated pages... nothing specific to your question

/* GET ITEMS
-------------------------------------*/
$items = $page->children($selector)->sort('-date');

//$items_per_page = 8;
$items_per_page = isset($items_per_page) ? $items_per_page : 8;
$start = ($input->pageNum - 1) * $items_per_page;
$total = count($items);
$items = $items->slice($start, $items_per_page);

// make this to give MarkupPagerNav what it needs
$a = new PageArray();

// add in some generic placeholder pages
foreach($items as $unused) $a->add(new Page());

// tell the PageArray some details it needs for pagination
// (something that PW usually does internally, for pages it loads)
$a->setTotal($total);
$a->setLimit($items_per_page);
$a->setStart($start);

$totalPages = ceil($total / $items_per_page);
Link to comment
Share on other sites

Thanks for the reply @Macrura. Really appreciated.

I start my first query, to return the first post: 

<?php $first = $pages->find('parent=/now/, sort=-now_date_posted, limit=1'); ?>

Then I do my second query, to return the next six posts:

<?php $then = $pages->find('parent=/now/, sort=-now_date_posted, limit=6, id!=' . $first); ?>

And finally the third query (the rest)

<?php $older = $pages->find('parent=/now/, sort=-now_date_posted, limit=2, id!=' . $first . '|' . $then); ?>

So you can see what it is doing; this is all part of the template that uses the pagination. The issues lies in when I go to page2, it goes through these stages again whereas it should just be using the $older query for everything onwards, which is why I used $older->renderPager(array()) for my pagination, which displays the right number of pages, but it is still using the same template. Can I limit the pagination return to only use the $older query?

Please see attached how it currently looks so you can see the desired outcome... the smaller items at the bottom is the $older query.

post-2553-0-16091900-1453990658_thumb.jp

Link to comment
Share on other sites

I know you said you have tried using start, but I only see one "start=1". I admit I haven't really read your code carefully, but the usual issue is that you need to put "start=0" in each of the selectors that is not the main page one - in this case it would be the "then" and "older" queries.

But as I said, I didn't read carefully so may be off on this one :)

  • Like 1
Link to comment
Share on other sites

Thanks, adrian. If I put start=0, then when I go to page2 they all just start at 0... whereas it should only be showing me a continuation of the final query... not all three queries. For example, page2 looks exactly like page1... but it should just be showing the 'older' query.

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...