Jump to content
brdje

Issues with rendering product catalog

Recommended Posts

Greetings,

 

I've created a product database which all use the template product.php and are published on the website.

I'm trying to create an overview table with pagination of all the products, but using $pages->get does not return an object, only the object title.

$products = $pages->get("template=product, limit=10");

This returns 10 strings in the frontend but not the object. When looping over the result set to get product fields, i get the following error:

Notice: Trying to get property 'title' of non-object

 

Because the product database is fairly large, i've added a pagination using the same query and this does return all the pages, but i can't click on the links that the paginator renders.

$results = $pages->find("template=product, limit=10");
					if($results->getTotal() > 10) {
						echo $results->renderPager(array(
							"nextItemLabel" => "Volgende",
							"previousItemLabel" => "Vorige",
							"currentItemClass" => 'active'
						));
					}

image.png.d8426092052466203c55c33d48f89e67.png

I've added the option in the template to allow page numbers. When i navigate to the link manually, i still end up seeing the 10 first products.

 

I've tried changing several settings around, but i'm a bit stuck on how to resolve these issues. Do you have any advice what I need to adjust?

Thanks in advance for your feedback.

 

 

Share this post


Link to post
Share on other sites

See the docs to understand the difference between $pages->get() and $pages->find():
https://processwire.com/api/ref/pages/get/
https://processwire.com/api/ref/pages/find/

You want $pages->find(). And you only want to execute it once and use $results for both the results list and the pagination.

$results = $pages->find("template=product, limit=10");

// Results list
foreach($results as $result) {
	// Output each individual result
	// ...
}

// Pagination
echo $results->renderPager(array(
	'nextItemLabel' => 'Volgende',
	'previousItemLabel' => 'Vorige',
	'currentItemClass' => 'active'
));

 

  • Thanks 1

Share this post


Link to post
Share on other sites

Thanks for the clarification. I did interpret that incorrectly and using find i get all the requested information correctly.

The pagination links still aren't working at the moment, where the issue remains the same. 

Links are present and rendered, but nothing happens when clicking them. Navigating to the url itself, will always render the first page of results wether being on page 1 or 1831 (current last page)

Share this post


Link to post
Share on other sites
1 hour ago, brdje said:

Links are present and rendered, but nothing happens when clicking them. Navigating to the url itself, will always render the first page of results wether being on page 1 or 1831 (current last page)

Enable pagination/page numbers in your template (the overview template) settings.

2019-11-28_13-43.png.5af108d74184d6ad6c3b1bbf7c77ce78.png

Share this post


Link to post
Share on other sites
2 hours ago, wbmnfktr said:

Enable pagination/page numbers in your template (the overview template) settings.

2019-11-28_13-43.png.5af108d74184d6ad6c3b1bbf7c77ce78.png

"Allow Page Numbers" was enabled in the template allready upon creating the template. But the pagination just doesn't work it seems.

image.png.db7b3ce3bd37f9e57e9062dfce328267.png

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By dragan
      Quick question: Is it possible to use PW's pagination for other things than PageArrays? i.e. query custom database tables and paginate the results? Has anyone ever tried it?
    • By jds43
      Hello,
      I have a search page loosely based on Skyscrapers where I'm parsing a selector with options 'beds', 'bathrooms', 'size' fields. It is working well until I select 'Any' after I've run a search. This is where no results are returned (/?beds=&bathrooms=&size=&submit=). I want it to reset and show all results.
      I hope this isn't too vague.
       
    • By Peter Troeger
      Hello Community 🙂
      Has anyone ever tried having multiple elements on one page that get their info with $pages->find('selector, limit=n') and tried using pagination on one of these elements without effecting the other?
      I have a slider on a page where I display content with pagination. But when I go to page two, the slider content also goes to page two, which I don't want it to do 🙂
      Any tips are greatly appreciated!
      Thanks!
      -Peter
    • By Peter Troeger
      Hello 🙂
      I have set up pagination on a mulitlanguage site.
      I've done this before, but this time I have a problem I can't solve.
      Pagination is activated on 'parent-template' and 'child-template' just to be sure 🙂
      This is my code:
      $children = $page->children('limit=1'); foreach($children as $child) { $title = $child->title; echo $title; } echo $children->renderPager(); The navigation is output correctly and the link look correct as well 'parent-page/page2/'.
      But when I click the link, the site seems to redirect back to 'parent-page/
      Any help would be greatly appreciated 🙂
      - Peter
    • By MateThemes
      Hello everyone!
      I have a problem with pagination. I have following code:
      <div class="uk-section"> <?php $results = $pages->find("template=gallery, limit=10, sort=title"); $pagination = $results->renderPager(); echo $pagination; echo "<ul class='uk-pagination uk-flex-center'>"; foreach($results as $result) { echo "<li><a href='{$result->url}'>{$result->title}</a></li>"; } echo "</ul>"; echo $pagination; ?> </div> Which works fine. And this markup results in following html code:
      <div class="uk-section"> <ul class='uk-pagination uk-flex-center'> <li> <a href='/galerie-bisheriger-projekte/'>Galerie bisheriger Projekte</a> </li> <li> <a href='/galerie-bisheriger-projekte/galerie-1/'>galerie-1</a> </li> </ul> </div> But instead of "Galerie bisheriger Projekte" and "galerie-1" I want to have a number.
      And as last question, how can I add a previous and next button?
      Thanks for your help!
×
×
  • Create New...