Jump to content

Problem with Pagination


CodeCoffeeCode
 Share

Recommended Posts

Hi fellow PW people.

This is my 1st time posting here. Being a html and css front-end guy I’m virgin to CMS development but picking up the art of programming fast thanks the user intuitive and friendly ProcessWire which ended up being my CMS of choice after a month of experimenting among several.

I’ve finally been presented with my first ‘unable to figure out’ problem…  ???

Ive been trying to tackle my head around a pagination problem. I am able to output the pagination however when you click on ‘page 2’ it directs to that page in the url, but the results don’t update. 'Page 2' outputs the results of 'page 1'. Also the navigation link stays on 'page 1' and the previous button don’t show.

I have read through the API docs and also consulted other forum posts relating to pagination, trying out various different options to no avail. 

I have also enabled pagination in the templates used by the output pages. So I’m left scratching my head hoping some clever PW pro can help me figure this out. Below is the code used for the output.

<?php foreach($results = $page->children("limit=6") as $child) 
echo "
  <div class=\"cottage-listing\">
    <div class=\"image\">
      <img src=\"{$config->urls->templates}/styles/images/examplecottage.jpg\" alt=\"Image of [cottage_name], [cottage_area]\">
    </div> 
    <div class=\"description\">
      <p>
      <span class=\"cottage\"><strong>$child->title </strong>$page->title, {$page->parent->title} </span>
      <span class=\"information\">[cottage_summary] - Limited to 120 Chars</span>
      </p>
    </div>
    <div class=\"info\">
      <span class=\"price\"><strong>from: £121</strong>per night</span>
      <dl>
        <dt>Type: </dt>
        <dd>{$child->cottage_type->title} | {$child->cottage_catering->title}</dd>
        <dt>Sleeps:</dt>
        <dd>{$child->cottage_sleeps}</dd>
        <dt>Rooms:</dt>
        <dd>{$child->cottage_bedrooms}</dd>
      </dl>
      <a href=\"{$child->url}\" class=\"button\">More Details</a>
    </div>
  </div>
";  ?> 

<?php 
$pagination = $results->renderPager(array(
// Controls the output of the pagination links
    'nextItemLabel' => "»",
    'nextItemClass' => "",
    'previousItemLabel' => "«",
    'previousItemClass' => "",
    'listMarkup' => "<ul class='pagination'>{out}</ul>",
    'itemMarkup' => "<li class='{class}'>{out}</li>",
    'linkMarkup' => "<a href='{url}'>{out}</a>",
    'currentItemClass' => "current",
    'firstItemClass' => "",
    'firstNumberItemClass' => "",
    'lastNumberItemClass' => "",
    'lastItemClass' => ""
));
if ($pagination ==""){
  echo ""; } 
else {
  echo "<div class=\"pagination-centered\"> $pagination</div>";
}
?>

Any suggestions are welcome. It is probably something stupid staring me in my face, but after several hours trying to figure it out myself I'm turning to the super supportive forum before I start pulling my hair out (what's left of it) .

Link to comment
Share on other sites

Sorry to be a bit picky, but I cannot find any issue with your code, so we check this:

I have also enabled pagination in the templates used by the output pages. 

Do you mean by "output pages" the children you're showing in the list? This would be wrong. You'd need to enable pagination on the template where you're rendering the list, not in the template of the list-items. The setting just enables, that ProcessWire parses the urlSegments correctly, this has nothing to do with the paginated content.

Link to comment
Share on other sites

What's the url when you go to page 2?

Is there something else special in your setup?

Otherwise I would say pagination is not enabled or you have other limit calls previously in your code.

Link to comment
Share on other sites

Hi Soma,

The URL when I go to page-2 is: " http://localhost:8888/LDVC-PW-DEV/adult/child/?page=2

There is nothing special in my setup. I'm basically running the  Latest PW Dev version with basic installation and one site module (ProcessPageFieldSelectCreator).

Pagination is certainly enabled on the template used to render the lists:

post-3666-0-13364900-1439497711_thumb.pn

And in regards to other limit calls previously in my code, I don't think there was any.

I have actually spent all day just trying to get my head around this... Including creating a new PW installation importing my template files and fields from the default. Enabling pagination in the templates... But it still does not work.

Link to comment
Share on other sites

Pagination is done by urlsegments so the url shouldn't have get strings, but rather an …/page2/ at the end of the url. And just to quote Ryan on that (comment on the pagination docs)

If you are seeing a URL like ?page=2 that indicates that pagination is not enabled for the template, and you would need to enable it.

Link to comment
Share on other sites

Only thing I can say is that /adult/child/?page=2

Actually

/child/?page=2

indicates that pagination is NOT enabled on the page you are on doing it, if it was it would be

/child/page2 

Link to comment
Share on other sites

LostKobrakai,

Okidoki, Just to prove to myself that I am not going insane, here is proof that I have the template set up so pagination is enabled. Forgive me if I am wrong, but Im 100% confident that this is all set up properly and the template is using the code I originally posted here. Unless I'm seriously missing something here.

Image one: Proves the core plugin is installed:

post-3666-0-80235900-1439500467_thumb.pn

Image two: Proves the template "location.php" has pagination enabled:

post-3666-0-95896800-1439500558_thumb.pn

Image three: Proves the template "location.php" is in use for the list results... with pagination enabled.

post-3666-0-40247800-1439500628_thumb.pn

In image 3, you can see it outputs the page template being used. You can also see that the Pagination Numbers are output to the page, and also that in the url it shows "foo/bar/?2".  If i click on the number one, it redirects the URL to "foo/bar/".  

I also tried limiting the pagination to return only 1 result per page, resulting on numbers 1,2,3,4 output to the pagination as there are only 4 sample child pages. And the same result applies when clicking on either of the numbers; it returns the numbers in the URL but not the results.

So am I missing something stupidly simple and basic here? I'm fairly certain I have done things correct but then again, my brain is almost in zombie state spending too much time trying to figure out this issue.

Link to comment
Share on other sites

Hi Wanze,

Ive not enabled any catching modules yet to my knowledge. Im going to double check everything now to ensure caching is off on all templates. Ive not installed any site modules for caching anything yet. I'll also clear my browser history and check the page in multiple browsers.

Link to comment
Share on other sites

Soma,

Yes, I want the children of this template to be paginated. I also what the child pages of the next level paginated... My Page structure is:

region template = central-lakes

location template = ambleside

HOME - ( home template )

- Region 1 ( region template ) paginates child pages ( Locations )

-- Location 1 ( location template ) paginates child pages (cottages)

--- Cottage 1 ( cottage template )

--- Cottage 2 ( cottage template )

--- Cottage 3 ( cottage template )

--- Cottage 4 ( cottage template ) 

-- Location 2 ( location template ) paginates child pages (cottages)
--- Cottage 1 ( cottage template )
--- Cottage 2 ( cottage template )
--- Cottage 3 ( cottage template )
--- Cottage 4 ( cottage template )

The code I originally posted represents this, (i think).

Link to comment
Share on other sites

That means that the page you're looking at, its template doesn't have page numbers enabled.

Can you change it to this?

echo "template: " . $page->template->name . " pagenum: " . $page->template->allowPageNum;
Link to comment
Share on other sites

Soma, LostKobrakai, Wanze

Many thanks for your time helping me try to figure this out... I did a fresh install of PW and imported the templates and fields (not including the cottage template). When I attempted to create a "region" page using the region template, I was thrown this error:

post-3666-0-57952000-1439560310_thumb.pn

Error #2 is what was causing the problem!!!!  -_-

As it happens I had this line of code in my "head" template (TMP_head.inc):

<div id="wrapper" <?php if ($page->template = cottage): echo 'class="cottage-listings"'?> <?php endif ?>>

When it should have been:

<div id="wrapper" <?php if($page->template == location) echo 'class="cottage-listings"'?>>

What an idiot I am  :rolleyes:...  Thank you all once again for your assistance and support.

  • Like 1
Link to comment
Share on other sites

Then your

<h1><?php echo $page->title; "Holiday Cottages"; if($page->editable()) echo "<p><a href='$page->editURL'>Edit</a></p>"; ?></h1>

also outputs title of cottage and edit link?

It's like you overwrite $page somewhere (header.inc?) or just the template like $page->template = "something" instead of $page->template == "cottage" ...

Strange, and I don't see what's wrong. Only thing I know is that you're viewing a page that template doesn't have pagination enabled.

  • Like 1
Link to comment
Share on other sites

Then your

It's like you overwrite $page somewhere (header.inc?) or just the template like $page->template = "something" instead of $page->template == "cottage" ...

Strange, and I don't see what's wrong. Only thing I know is that you're viewing a page that template doesn't have pagination enabled.

Yes, it was a problem with the code in my head.inc template... Sorry for taking your time to help me with this, as it was such a stupid and simple issue that should not have happened if I had been paying more attention to what I was trying to do... Lesson Learnt!! Many thanks

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