Jump to content

Pagination: Each page showing same content?


MarcC
 Share

Recommended Posts

I tried to adapt the pagination code shown in the API docs, but I'm getting the same items (first 8 ) shown on each page as I go through the pages. Any ideas what I may be doing wrong? Thanks.

<!-- Portfolio List-->  
<div id="portfolio-list" class="content">

<?php 

	$results = $page->children->find("limit=8, sort=title");

	$pagination = $results->renderPager();

	foreach ($results as $i) {

		$firstimg = $i->images->first();

		$f700 = $firstimg->size(700,500);

		echo "
			<div class='four columns module-container {$i->parent->name}' style='padding-bottom:20px'>\n\t				
				<div class='module'>\n\t						
					<div class='module-img'>\n\t							
						<a href='{$i->url}' title='View item details'>\n\t
							<img src='{$f700->url}' title='{$f700->description}' alt='{$f700->description}' />\n
						</a>\n									    
					</div>\n
					<div class='module-meta'>\n\t
						<h5>{$i->title}</h5>\n	
						<hr class='half-bottom' />\n
						\${$i->Price}\n
						{$i->body}\n
					</div>\n						
				</div>\n
				<span style='display:block;'><a href='{$i->url}'>{$i->title}, \${$i->Price}</a></span>	
			</div>\n\n\n
			";

		}

		echo $pagination;

?>

</div>
<!-- /End Portfolio List-->	
Link to comment
Share on other sites

Nope, that one was already checked. I did just upgrade to the latest PW version and I'm getting the same issue. The URL does change to /page2, etc but the list items remain the same, as well as the pagination index created by the render function.

Link to comment
Share on other sites

Sorry, I should have noticed this the first time, but here's the problem:

$results = $page->children->find("limit=8, sort=title");

The $page->children call is actually causing all the children to be loaded, and then you are post filtering in memory. Since all the children are already loaded, it's not attempting to do any pagination. Replace it with this and it should start to work:

$results = $page->children("limit=8, sort=title"); 
Link to comment
Share on other sites

  • 5 months later...

About 5 month later, I have nearly the same problem and can not explain to myself what's going on.

I want to use pagination on the homepage/ root page. I created a homepage template that displays articles from this structure:

/homepage/articles/article.

So I try to paginate all the single articles lying beneath "/homepage/articles/" (hope this is not confusing). It's

HOME

ARTICLES
Article 1
Article 2
Article 3
...

I was trying this code:

$results = $pages->find("template=article, limit=15, sort=title");

if(count($results)) {  
$pagination = $results->renderPager(array(
	'nextItemLabel' => "next",
	'previousItemLabel' => "prev",
	'listMarkup' => "<ul class='MarkupPagerNav'>{out}</ul>",
	'itemMarkup' => "<li class='{class}'>{out}</li>",
	'linkMarkup' => "<a href='{url}'><span>{out}</span></a>"
));  

echo $pagination;

echo "<ul>";
foreach($results as $result) {
	echo "<li><p><a href='{$result->url}'>{$result->title}</a><br /><span class='summary'>{$result->articleDescription}</span></p></li>";
}
echo "</ul>";

echo $pagination;

}

As result, I get the pagination navigation, but it's not working correctly. Clicking through the pages shows always the same results.

This query didn't work eather:

$results = $page->child("title=articles")->children("limit=5");

Any ideas? I was now trying for hours...

  • Like 1
Link to comment
Share on other sites

When pressing the links you get a clean URL? If not I would bet you still have to check the "allow page numbers" on the template like Ryan suggested above.

Link to comment
Share on other sites

@jan and all, thanks, this thread finally got me started on Pagination, I've tried for hours and got nowhere until now and I don't really know why, this has been a hard problem to solve for my small brain. Now to loose the numbering and just have Next and Previous being in lumpt of 5 posts at a time (wish me luck ;))

Link to comment
Share on other sites

@alan: I just corrected a small mistake in the code above. If you want to check if there are any results for your query than you can use

if(count($results)) {
...
}

(before I wrote if($results) which does not work.)

Good luck and have fun, I'm still in love with ProcessWire :D Sometimes I'm also wondering about my brain....

I'm not sure, if I got your post right (my english is not very good at all...), but if you do not want to show all the page links (== numbers), you can try the option numPageLinks like

$pagination = $results->renderPager(array(
  'numPageLinks' => 3
));

I didn't try it, but perhaps 0 is also allowed as value, if you only want to show 'prev' and 'next' buttons.

Reference of all options is at the bottom of this page:

http://processwire.c...rkup-pager-nav/

Link to comment
Share on other sites

@jan thanks for posting the correction! :)

Yes I'm still loving PW too, and I think this will be a permanent thing, because of it's excellent API (instead of having to use lots of plugins like many other CMSs).

Thanks for the suggestion, yes, I saw that numPageLinks and I assumed '0' would turn it off, but it doesn't seem to :( But I'll keep looking for how to do this ;)

Link to comment
Share on other sites

Alan, you don't necessarily need to use PW's MarkupPagerNav module if all you need are next/prev links. Here's how you might do it instead with your own code:

$limit = 5; 
$items = $page->children("limit=$limit"); 
$prev = $input->pageNum > 1? $input->pageNum-1 : 0;
$next = $items->getStart() + $limit < $items->getTotal() ? $input->pageNum+1 : 0;
if($prev) echo "<a href='{$page->url}page{$prev}'>Prev</a> ";
if($next) echo "<a href='{$page->url}page{$next}'>Next</a> ";

If you prefer to use the MarkupPagerNav module instead, then you could always just hide the numbered links with CSS:

ul.MarkupPagerNav li {
   /* hide all the links */
   display: none; 
}

ul.MarkupPagerNav li.MarkupPagerNavNext,
ul.MarkupPagerNav li.MarkupPagerNavPrevious {
   /* display just the next/prev items */
   display: inline; 
}
  • Like 1
Link to comment
Share on other sites

THANKS for this Ryan, examples like this are so helpful to me.

I've been so enthused by the power and flexibility of PW I've bought a book that was recommend here on the forum in the hope I end up needing less and less of these brilliant examples as time goes by :) Cheers!

Link to comment
Share on other sites

Looks like a good book Alan. Let us know how you like it. I've been hunting for new books, but have lately found more of the kind of content I'm looking for online than in books. Most recently I've been enjoying this site: http://phpmaster.com/ ... grabbing articles with Readability and reading them offline on the iPad and Kindle.

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