Jump to content
Sign in to follow this  

Page rendering limits other queries in sidebar

Recommended Posts

Hello guys. I am super happy to be passing to the final cleanup of my first custom build theme and to start applying the SEO optimization modules/code. I noticed something strange this morning and can't find out where exactly is my issue. Hopefully it is a quick fix or silly miss on my side.

So here is the issue: I am generating a list of all my recipes in the db using the following query:

<?php 	if($page->numChildren) {

//Build a selector and limit page results to 10
$recipe_results = $page->children("limit=4");

//Assign results of the array to $listing
foreach($recipe_results as $index => $listing) {

//Limit the text content to 160 chars using the function in function.php
$text = $sanitizer->textarea(truncate("$listing->recipe_intro_text", 160));

Then follows the boring part of html insert of the variables, clases etc. The listing works fine. So as far as there would be more than the planned results per page, I implemented the page rendering using the following code:

<!-- Pagination -->
echo $recipe_results->renderPager(array(

//Show font awesome right hand icon for next page
'nextItemLabel' => __("<i class='fa fa-hand-o-right'></i>"),

//Show font awesome left hand icon for previous page
'previousItemLabel' => __("<i class='fa fa-hand-o-left'></i>"),	

//Define the active class of current page
'currentItemClass' => "current",

//Define the block markup code
'listMarkup' => "<ul class='page-nav'>{out}</ul>",

//Define the item markup code and applying currentItemClass
'itemMarkup' => "<li class='{class}'>{out}</li>",

//Generating the link appearance of all buttons
'linkMarkup' => "<a href='{url}'>{out}</a>",  

<!-- Pagination -->

And again, everything worked perfectly after I allowed page numbers. 

So then I implemented a few similar queries in the sidebar of my website, listing content from other page parents/children. Here is one example:

	$favorite_books = $pages->find("template=books-inner, sort=-random, limit=3");
	foreach($favorite_books as $b) { 
	if (count($b->book_images)) {
	$thumb = $b->book_images->first->size(70,60)->url; 
	$desc = $b->book_images->first->description;
	else {
	$thumb = $settings->small_thumb->url;
	$desc = "NoThumb";

	<div class="thumb">
		<a href="<?php echo $b->url?>">
			<img src="<?php echo $thumb?>" alt="<?php echo $desc?>"/>
	<div class="detail">
		<a href="<?php echo $b->url?>"><?php echo $b->title?></a>

<?php } ?>


It was all working fine, until I started browsing page 2, 3, etc. It appears for some reason, that the pageRendering is applied not only to $recipe_results, but also to all requests from the widgets. So on page 1, I get the proper number of recipes and proper number of results in the widgets (books in this example). If I browse to page two, I still see the proper recipes number and everything else, but the widgets show only 1 result (as far as I have imported 4 test posts only). On page 3, it shows notihing in the widgets, but recipes are OK again.

As far as to render pages I am using $recipe_results and the pageRender is called for that variable, I am not sure why it is also applied to $favorite_books and other widgets. Any suggestions or ideas what is going on? I tried to change every variable on the page thinking that I might be having a call to the same one, but it is obvious in the example that they do not match...

Share this post

Link to post
Share on other sites

That's the normal behaviour. Have a look at this thread for a solution:


  • Like 3

Share this post

Link to post
Share on other sites

@kongondo Thanks for the link. I checked it up and it is interesting approach, however it seems like the post author was trying to render two sources on the same page and paginate the results where in my case I am just trying to show the results of two queries but pagination is needed only for the one.Will try to test the solution provided there, but it is not yet clear for me how that approach would fit in my scenario.

Edit: I found a simple way to fix the issue, and it was right under my nose in the pagination markup explanationTo make the queries work where I do not want the PageRendering to happen, I just added start=0 into the find query:

$favorite_books = $pages->find("template=books-inner, sort=-random, start=0, limit=3");

Thanks again for pointing me to the initial link which gave me an idea how to phrase my search and bring me to the right spot. As far as I wanted to pull N-random requests, it works perfect. One more step closer to the end ;)

  • Like 2

Share this post

Link to post
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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • 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!
    • By dragan
      Is it somehow possible to limit the number of pages one can select with the page reference field?
      I have a case where I need to have exactly three, not more, not less. Is this doable with a hook? Or would you suggest another approach? (three single pageref fields and make each mandatory)
    • By cappuccino
      I'm trying to creat a widget and add it to ckeditor. I found this tutorial, but something I make wrong.
      First I downloaded this plugin (https://ckeditor.com/cke4/addon/widget). I extracted the downloaded plugin in site\modules\InputfieldCKEditor\plugins. Then I started with the simplebox tutorial. I added a new folder ("simplebox") in site\modules\InputfieldCKEditor\plugins and followed the steps in the tutorial. But I'm struggeling with the part "CKEditor Initialization". I selected "simplebox" and "widget" in the 'extra plugins' section of the field config, but there are no extra toolbar buttons. If I open the page with the textarea there is only a empty field (s. picture). Could you help me?

    • By chuckymendoza
      Hello together,
      I have a problem with the image field and in my case it seems that there is a limit of how much images can be in such field.
      The following case:
      I have around 20 pages. Each has a usual image field, where I can upload an unlimited number of images (array).
      Most of the pages got 50-200 images but one page got 411 images (I know, it’s much  )

      Now, when I change the order of one image (let’s say I drag & Drop the first image after the third) or delete one image by clicking on the trashcan, everything runs fine. BUT when I click SAVE the image won’t be deleted or moved to it’s new place. You can change anything else on the page - I have a text field there - and save it, no problem.
      Interestingly I can add (upload) new images but I’m not able to delete or move them.
      - The file size of the images are between 200kb and 1.7MB, RGB, JPGs.
      - When I duplicate the page and try to delete/move I got the same problem.
      - I also created a whole new page and got the same problem
      - Also tried a different server (virtual and online): same problem
      - ProcessWire 3.0.62
      So, is there a limited to the images field? Any clues except limiting the image files to max. +-200 images?
      Thanks so much in advance and have a great weekend.
    • By ridgedale
      Reference: PW 3.0.62 and uikit3 based site using the Reglar-Master profile.
      I'm trying to add a count of the number of category posts to display beside each of the category titles listed in the sidebar on the blog page.
      The following code displays the total number posts on each category page:
      <span class='uk-text-muted'>Total <?php echo page()->title; ?> posts: <?php echo count(pages()->get('/blog/')->children("categories=$page")); ?></span> The following default code displays the heading and a list of the categories:
      <?php $categories = pages()->get('/categories/'); echo ukNav($categories->children, [ 'header' => $categories->title ]); ?> but I want to add the respective number of posts on the same line as each category title listed. When I try replacing the default code with the following:
      <?php $categories = pages()->get('/categories/'); $catposts = count($categories->children("categories=$page")); echo ukNav($categories->children . ' ' . $catposts, [ 'header' => $categories->title ]); ?> I get the following error:
      which refers to the following code in the _uikit.php file:
      $page = $items->wire('page'); // current page and when I try:
      <?php $categories = pages()->get('/categories/'); $catposts = count($categories->children("categories=$page")); echo ukNav($categories->title); foreach ($categories as $category) { echo $category->children . ' ' . $catposts; } ?> or:
      <?php $categories = pages()->get('/categories/'); $catposts = count(pages()->get('/blog/')->children("categories=$page")); echo ukNav($categories->title); foreach ($categories as $category) { echo $category->children . ' ' . $catposts; } ?> I get the same error.
      If I change
      I get the following error messages:
      Any advice on where I am going wrong would be very much appreciated.
  • Create New...