Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save anilex/d24d335e0c64276bdcaf600525cd5b99 to your computer and use it in GitHub Desktop.
Save anilex/d24d335e0c64276bdcaf600525cd5b99 to your computer and use it in GitHub Desktop.
Generate ProcessWire pages with random titles, body and image
<?php
for ($i = 1; $i <= 20; $i++)
{
$title = file_get_contents("http://loripsum.net/api/1/plaintext/long/prude/");
$body = file_get_contents("http://loripsum.net/api/3/decorate/link/ul/prude/long/");
$template = "INSERT_TEMPLATE_HERE"; // i.e. 'basic-page'
$parent = "INSERT_PARENT_HERE"; // i.e. /about-us/
$c = new Page();
$c->template = $template;
$c->title = implode(' ', array_slice(explode(' ', $title), 8, 11));
$c->body = $body;
$c->parent = wire()->pages->get($parent);
$c->news_date = date("Y-m-d", strtotime( "+" . mt_rand(0,30) . " days")); // Create a random date in the next 0 to 30 days
$c->save(); // Save first because we need an directory to place the files in
$c->news_image = "http://placehold.it/450x350";
$c->save(); // Save again to append the image
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment