Search the Community

Showing results for tags 'random'.

More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


  • Welcome to ProcessWire
    • News & Announcements
    • Showcase
    • Wishlist & Roadmap
  • Community Support
    • Getting Started
    • Tutorials
    • FAQs
    • General Support
    • API & Templates
    • Modules/Plugins
    • Themes and Profiles
    • Multi-Language Support
    • Security
    • Jobs
  • Off Topic
    • Pub
    • Dev Talk

Found 9 results

  1. Following the example from the PW docs I set up a a repeater. I'm trying to fetch random fields from a repeater, for instance, display 4 random customer testimonials. Here is the basic setup in PW: created these fields: testimonial_text testimonial_name I then added them to a repeater field called: testimonials_repeater Next I added testimonials_repeater to a template called testimonials Last, I created a new page called Testimonials using the testimonials template. As far as fetching all the testimonials I'm doing this: <?php $testimonials = $pages->find("template=testimonials"); foreach($testimonials as $trepeater) { foreach($trepeater->testimonials_repeater as $t) { echo $t->testimonial_text . ' -' . $t->testimonial_name; }} ?> Could some please give me some guidance on how to pull, for instance, 4 random testimonials? I mean, I could stick the results in an array[] inside the foreach loops, then random sort the array, then output only 4, but there has to be a better way using PW. Also, is there a way to limit the number of records (customer testimonials) that can be added by the user? Repeaters just always seem to trip me up. :/ thanks much!
  2. Posting in the hope this helps someone out of a hole! Having built 20+ sites on PW in the last couple of years (and loving it...) I came across a really odd situation recently. The client's IT company and I 've been battling for a couple of weeks and today, finally, we have an answer! The site is built and temporarily housed on a shared hosting account we have for development. All tested well here so Access was granted to the client to start adding content. The next day I get a call from the client to say the admin side of the site is logging them out every 30-40 seconds and they have to log back in again each time to continue. I tested again from our office with their login but all worked as expected. Other browsers, PCs etc. were all tried by the client but the problem persisted. So, I get in my car and drive to the client's site. Sure enough, I see the issue on one of their iMacs. So I open up my MBP, connect to their network, log in as them and the problem is there. So, next, I came off of their network and onto my tethered iPhone on 4G. Bingo! The problem goes away. So it's their network that's the issue. Their IT company were called and, with us helping them wherever possible, they worked on it for 2 weeks to find the problem. I captured the port numbers in use by PW admin (60992, 60993, 61000, 61001, 61002, 61003 by the way) and the IT company opened those ports on the router but still, the problem remained :-( And then the breakthrough... They have two VDSL lines into the building that feed their router through a load balancer. It seems that their setup meant that responses to outbound traffic did not necessarily come back in via the same line. Processwire admin does not like this! So, the IT company put in a rule to direct all traffic from the IP of the shared hosting through the same route in and out of the building and BOOM! it all works as expected. Phew! All's well that end's well but it certainly put us through the wringer tracking it down. Actually, I think it's pretty cool that PW does this. A good extra security measure. Several other CMSs (no names...) worked just fine with this scenario but not PW. Anyway, happy client, happy me. Hopefully, this story helps someone else here too.
  3. $items = $pages->find("template=city, sort=random, limit=20"); I'm using find to get 20 random items, is there a way to use a seed so i can paginate them?
  4. Hello, Getting random pages with $oldPosts = wire('pages')->find('template=post, shown=1, limit=100')->findRandom(16); works fairly good. About 500ms But without the limit=100 it takes more than 6 seconds. There are only 60 pages with template post but it will be thousands when the app is live. Is there a more efficient way of getting random pages?
  5. Hey Guys! I ran into some really strange behavior when trying to save selected Selectfieldtype values from a form to a select field in a page. I have three different dropdowns in this page, all with different values and they randomly get saved en sometimes they don't. This is my setup: Form Page: Dropdown a: Dropdown a: - - V - - - V - Dropdown b: Dropdown b: - - V - - - V - Dropdown c: Dropdown c: - -V - - - V - I have no idea what is causing this since it happens completely randomly, does anybody have any ideas? Like, would it make more sense to only use a text field on the page side to recieve the value? and if so, why? Thanks in advance Gr, Bram PS: In the screenshot you can see the three filters that pick up the dropdown values and show the entries that are equal to the filter. And you can see the dropped values in the submissions.
  6. Hello All! This is my first post here and am a newbie with PW. So far I've been able to accomplish everything I've wanted to do dynamically in my first PW site, but ran into a big snag yesterday. Ok here's the setup: I have on my site 4 pages that deal with separate plumbing services. We offer a discount coupon for each service. For each service, I am displaying it's coupon image in the sidebar. Each coupon image resides in the images field of the individual rootParent parent services page, and each image has a tag of "coupon" assigned to it. So for example, I have a rootParent level "Drain Cleaning" page and it is in this page's images field that the Drain Cleaning coupon image resides with the tag "coupon." The next coupon resides in the images field for my rootParent "Sewer Cleaning" page, and so on. For each service page, I have some Hanna Code I wrote to include the coupon image in the sidebar of the rootParent and all of it's children: $coupon = $page->rootParent->images->getTag('coupon'); This works great! Now, here's my problem... For pages other than the service pages, like form confirmation pages, the Contact Us page, etc., I still want to display a coupon image in the sidebar, but I want to grab a random coupon image and display it. So far, I have not found a way to successfully scan all page's images field, grab the images with the tag of coupon, then display a random image. Here is the code I've come up with so far that is not working: First, build the array of pages containing an image with the tag of coupon (this works): $couponpages = $pages->find("images.tags=coupon"); Next, get the images tagged coupon from the array of pages containing them (this is where the code breaks and throws an error): $coupons = $couponpages->images->getTag("coupon"); The error reads: "Fatal error: Call to a member function getTag() on a non-object." Beyond that, I would then want to fetch a random image and display it: $coupon = $coupons->getRandom(); echo "<img alt='{$coupon->description}' src='{$coupon->url}' />"; If anyone can help me solve this it would be most appreciated! Thanks, Dave
  7. Hi, I'm trying to combine two find() arrays in a random order but currently can only make it give me back the same order each time. here's what im working with: $works = $pages->find('template=work'); $articles = $pages->find('template=article'); $works->prepend($articles); $randWorks = $works->getRandom(count($works)); foreach($randWorks as $child) { $class = $child === $page->rootParent ? " class='active'" : ''; echo "<a$class href='{$child->url}'>{$child->title}</a>"; }
  8. Hello, I'm trying to change all upload image files names for the random names. So I put in Pageimage.php this lines: $rand = substr(md5(microtime()),rand(0,26),5); $basename = basename($rand, "." . $this->ext()); // i.e. myfile But as a results I got a lot of random filenames during each page loading. Please advise what do I miss? Thanks, AP
  9. So I tried using $page->repeater->getRandom() in some template code but it didn't seem to work. Should this work? If not, what is the recommended way of working with a single, randomly-chosen repeater item? Thanks!