ProcessWire
Recipes_

Get random page via API, e.g. from a pool of testimonials

Problem

You have a pool of pages, e.g. quotes/testimonials, and want to display a random one.

Solution

A little example how to pull a random page:

$quote = $pages->find("template=quote, include=hidden, sort=random, limit=1")->first();

if($quote->id) {

	$q = $quote->quote; // example field
	$a = $quote->author; // example field

	echo "<blockquote>\n";
	echo "	<p>$q</p>\n";
	echo "	<footer>β€” <cite>$a</cite></footer>\n";
	echo "</blockquote>\n";

}

Resources