processwire-recipes / Recipes

Recipe Markdown files
29 stars 18 forks source link

New proposal for quick-first-child-redirect #26

Closed dsdsdsdsdsds closed 9 years ago

dsdsdsdsdsds commented 9 years ago

I'm using this first child redirect on a few of my sites. Maybe it's a better fit for most situations as it takes into account if the child is actually published and not hidden and also marks the redirect as temporary (because the first child most probably changes over time). What do you think?

// 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);
marcus-herrmann commented 9 years ago

Good enhancement, thanks!

marcus-herrmann commented 9 years ago

Online: https://processwire-recipes.com/recipes/quick-first-child-redirect/