Skip to main content

Questions tagged [random]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
2 votes
1 answer
209 views

How to show entries randomly

I want to show entries (hundreds) for signed-in users randomly, I use this: .order('RAND()') and in the same time make sure to loop over all entries before start showing the entries that have been ...
Mohamed's user avatar
  • 21
0 votes
1 answer
71 views

Get random entries order at each page load, but avoid repetitions

The easiest way to get a entries sort by random is to apply this: .orderBy('RAND()'). This is very useful, however I have a case where I need to get entries (which are adverts) in a random sequence ...
Romain P.'s user avatar
  • 1,852
2 votes
1 answer
122 views

Sprig load more: prevent repeating entries with random output

On an article page i show 3 random entries, and a load more button via sprig. {% set query = craft.entries().section(section).orderby('RAND()').offset(offset).limit(3) %} {% set items = query.all() %}...
Henrik's user avatar
  • 425
1 vote
1 answer
109 views

weighted random order

I have a field in a channel called "weight" where the user can set a number between 0-1000. On page load I want to generate a random number between 0 and "weight" for each entry, and then sort the ...
David André Erichsen's user avatar
3 votes
3 answers
974 views

Pagination with randomly ordered entries

I have a need to list a set of entries 9 at a time but with a random order. The pagination happens via Ajax, with each next set of 9 entries loaded onto the page when the user clicks the "See more" ...
foamcow's user avatar
  • 2,029
2 votes
1 answer
587 views

Get an image from a random entry

I have a section with an text field and an image field. the asset field may sometimes be left blank. in this case, in my template, i want to grab the image from another random entry. This is the code ...
artmem's user avatar
  • 1,022
1 vote
1 answer
411 views

Random posts displayed but exclude current entry ID

I am brand new to Craft and can't find much support on this problem online. I have my entry pages and at the bottom of them, I have a div with the code below in it which randomly links to any entry. ...
leham789's user avatar
1 vote
1 answer
191 views

Retrieve entries by random sort, then resort alphabetically

I need to pull X entries with {% set randEntries = craft.entries.section('presenters').order('RAND()').limit(10) %} But then sort them alphabetically on entry.lastName. Do I need to Supersort for ...
4midori's user avatar
  • 656
2 votes
1 answer
185 views

Selecting a random entry based on conditional

I'm trying to select 1 random entry out of a section based on whether a field has content (schedulerBio). I can get all the entries based on the conditional but can't seem to randomize a single ...
glider's user avatar
  • 647
1 vote
1 answer
233 views

Pull random image from entries marked with a certain category

I am trying to pull an image from services marked with a category of left. I would only like to display one image. I would also like to randomize the image if possible from all the images marked left. ...
bjyama's user avatar
  • 21
2 votes
1 answer
104 views

Adding a random entry to an array

I have a navi on which one entry consists of a random channel entry from one section among standard singles: Single 1 Single 2 Random Channel entry Single 3 I thought about something like this: {% ...
KSPR's user avatar
  • 3,786
1 vote
1 answer
3k views

Apply 'random' to an array

How do I output one random line of an array? {% set img = [ { bildli: 'http://i.giphy.com/I0xDz0htjsiME.gif' }, { bildli: 'https://i.giphy.com/fA3JALhIi5YVa.gif' } ] %} {% for item in img %} ...
KSPR's user avatar
  • 3,786
1 vote
1 answer
189 views

Random quotes in matrix block type

I have a Matrix block with 2 types: quotes and text. The first block contains a quote and a text. The second and following ones only contain quotes. I want the type text to be limited to 1 and the ...
Robbie Post's user avatar
1 vote
1 answer
198 views

Random Field Entries

I am working on a site for a client who posts many jobs for chefs. A lot of the jobs are essentially similar, so writing the job postings is something I am trying to simplify. I can write a series ...
Pathfinder's user avatar
2 votes
1 answer
453 views

How can I limit the output of assets randomly if an asset exists?

How can I limit the output of assets based on this criteria? search all entries randomly in section "homes" for only entries with at least one asset image limit those results to 8 random assets I ...
Bryan Garrant's user avatar
3 votes
1 answer
906 views

Can random be used for ordering with related/assets, in cached code?

I'm trying to determine if I can update this: {% cache %} [ {% set tags = craft.tags.group('color','season','style','venue').limit(null) %} {% for image in craft.assets.relatedTo(tags).order('...
Mark J. Reeves's user avatar
3 votes
2 answers
578 views

Output random blocks from a matrix but without the first

I have quotes inside a global matrix which i want to output randomly on the homepage but without the first quote-block. this does not work: {% set quotes = city.cityBlocks.offset(1) %} {% set ...
portnull's user avatar
  • 490
6 votes
2 answers
1k views

How do I get a random entry's URL from a Entries field?

I have a Entries field and I'd like to return a URL for one randomly picked entry. I could loop through all the entries, but I'd like to do something more efficient. Can I return an array of URLs? Or ...
Simon Kuran's user avatar
  • 3,015
14 votes
2 answers
2k views

How can I return data from a Matrix field in random order?

I have a slideshow with slide data managed in a Matrix field. How would I go about randomizing the data returned in the template so the slides show in a different order on each page load?
Anna_MediaGirl's user avatar