Jump to content


Photo

Pagination: Each page showing same content?


  • Please log in to reply
15 replies to this topic

#1 MarcC

MarcC

    Sr. Member

  • Members
  • PipPipPipPip
  • 255 posts
  • 63

  • LocationCalifornia

Posted 30 October 2011 - 11:41 PM

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

I'm a freelance, processwire-using web designer based in california. work site | personal site | visuals


#2 ryan

ryan

    Hero Member

  • Administrators
  • 5,780 posts
  • 3125

  • LocationAtlanta, GA

Posted 31 October 2011 - 08:16 AM

Check the template where the pagination is and click on the URLs tab. Check the box for "allow page numbers" – Let me know if that's it?

#3 MarcC

MarcC

    Sr. Member

  • Members
  • PipPipPipPip
  • 255 posts
  • 63

  • LocationCalifornia

Posted 31 October 2011 - 09:34 AM

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.

I'm a freelance, processwire-using web designer based in california. work site | personal site | visuals


#4 ryan

ryan

    Hero Member

  • Administrators
  • 5,780 posts
  • 3125

  • LocationAtlanta, GA

Posted 31 October 2011 - 11:07 AM

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");




#5 MarcC

MarcC

    Sr. Member

  • Members
  • PipPipPipPip
  • 255 posts
  • 63

  • LocationCalifornia

Posted 31 October 2011 - 02:38 PM

Hey, that worked! "Post filtering in memory" is a new one to me but I'll save the snippet so I don't forget it later. :-) Thanks Ryan!

I'm a freelance, processwire-using web designer based in california. work site | personal site | visuals


#6 jan

jan

    Jr. Member

  • Members
  • PipPip
  • 16 posts
  • 1

Posted 05 April 2012 - 08:20 AM

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

#7 diogo

diogo

    Hero Member

  • Moderators
  • 2,010 posts
  • 1089

  • LocationPorto, Portugal

Posted 05 April 2012 - 08:58 AM

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.

#8 jan

jan

    Jr. Member

  • Members
  • PipPip
  • 16 posts
  • 1

Posted 06 April 2012 - 10:46 AM

Stupid me... I thought the displaying numbers are showing that page numbers are already enabled in template.
You're completly right... Thanks a lot!

#9 diogo

diogo

    Hero Member

  • Moderators
  • 2,010 posts
  • 1089

  • LocationPorto, Portugal

Posted 06 April 2012 - 11:00 AM

You're welcome! I had the same problem recently :)

#10 alanfluff

alanfluff

    Sr. Member

  • Members
  • PipPipPipPip
  • 405 posts
  • 118

  • LocationOttawa, Canada

Posted 08 April 2012 - 11:59 AM

@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 ;))

#11 jan

jan

    Jr. Member

  • Members
  • PipPip
  • 16 posts
  • 1

Posted 09 April 2012 - 03:36 PM

@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/

#12 alanfluff

alanfluff

    Sr. Member

  • Members
  • PipPipPipPip
  • 405 posts
  • 118

  • LocationOttawa, Canada

Posted 09 April 2012 - 04:51 PM

@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 ;)

#13 ryan

ryan

    Hero Member

  • Administrators
  • 5,780 posts
  • 3125

  • LocationAtlanta, GA

Posted 10 April 2012 - 10:34 AM

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; 
}


#14 alanfluff

alanfluff

    Sr. Member

  • Members
  • PipPipPipPip
  • 405 posts
  • 118

  • LocationOttawa, Canada

Posted 10 April 2012 - 10:44 AM

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!

#15 ryan

ryan

    Hero Member

  • Administrators
  • 5,780 posts
  • 3125

  • LocationAtlanta, GA

Posted 10 April 2012 - 12:38 PM

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.

#16 alanfluff

alanfluff

    Sr. Member

  • Members
  • PipPipPipPip
  • 405 posts
  • 118

  • LocationOttawa, Canada

Posted 10 April 2012 - 01:43 PM

Will do do Ryan and thanks for the site, that looks good too.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users