Jump to content
onjegolders

Limit siblings AFTER removing $page

Recommended Posts

Am trying to list 3 other events (siblings) at the bottom of an event page.

My problem is I can only seem to limit before I remove the $page part meaning I end up with only 2 other events at the bottom of the page.

Have tried the following but doesn't seem to work:

$page->siblings->remove($page);
$events = $page->siblings("limit=3");

I've tried various things but perhaps someone more knowledgeable could point me in the right direction?

Thanks :)

Share this post


Link to post
Share on other sites

Direction:

$events = $page->siblings->remove($page)->find("limit=3");
  • Like 1

Share this post


Link to post
Share on other sites

You could also do this:

$events = $page->siblings->remove($page)->slice(0,3); 

but this may be better:

$events = $page->siblings("id!=$page, limit=3"); 
  • Like 1

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
      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 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.
      Thomas
    • By Peter Knight
      I have about 50 pages which are just containers for their child pages.
      What's the most efficient way to exclude these parent pages from Searches?
      I'm using Ryan's code here
       
      I guess I have a few options but is number 2 here the best way or is there anything I haven't considered which would be better?
      1. Mark as 'Hidden: Exclude from lists and searches"
      Isn't an option because it hides from lists which I use.
      2. Tell the selector to ignore a particular template(s)
      Sounds like a good approach
      3. Create my own checkbox called "Search Ignore" and add it into a selector
      Could work but it seems like a ton of work to manually edit all the pages I want to ignore
      Cheers
       
       
       
       
       
       
       
       
       
    • By MilenKo
      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 --> <?php 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:
      <?php $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"; } ?> <li> <div class="thumb"> <a href="<?php echo $b->url?>"> <img src="<?php echo $thumb?>" alt="<?php echo $desc?>"/> </a> </div> <div class="detail"> <a href="<?php echo $b->url?>"><?php echo $b->title?></a> </div> </li> <?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...
    • By Hubris
      Hi folks,
      My maximum file size upload tops at 50Kb, no matter what the browser or OS.
      My PHP settings are:
      enabled extensions:
      imagick, imap , json, mailparse, mbstring , pdo , pdo_mysql  and pdo_sqlite
      options:
      allow_url_fopen On display_errors Off error_reporting E_ALL file_uploads On include_path .:/opt/alt/php56/usr/share/pear:/opt/alt/php56/usr/share/php log_errors On mail.force_extra_parameters no value max_execution_time 180 max_input_time 180 max_input_vars 1000 memory_limit 256M open_basedir no value post_max_size 128M session.save_path /tmp short_open_tag On upload_max_filesize 256M  
      These settings here changed based on some tips of other topics on this forum.
      On the field, there is no min/max image dimensions.
       
      Thanks!
×
×
  • Create New...