Quick ProcessWire first child redirect snippet

Problem

From time to time it happens on a website project that you don't really have pages with teaser- or distributing-functions, but are in need for a first child redirect.

Solution

Use ProcessWire API to redirect:

<?php
/**
 * Template: First Child redirect
 *
 */

// if current page has children (published, not hidden), redirect (HTTP 302) to its first child
if($pages->count("parent=$page")) $session->redirect($page->child->url, false);

Version

1.0.4

View/correct recipe on GitHub

https://github.com/processwire-recipes/Recipes/blob/master/quick-first-child-redirect.md

Author(s)