Perch CMS Tip: Redirect to first subpage
March 29th, 2017 Web DevPerch CMSI've used this for my last few sites and thought I'd drop it here in case it helps someone else. Often, I'll have a page structure such as:
About (/about)
-- Our Team (/about/our-team)
-- Our Facilities (/about/our-facilities)
-- Our Mission (/about/our-mission)
In this case, /about doesn't necessarily need its own page, so I've created a master page to automatically redirect to the first subpage.
Master page: perch/templates/pages/redirect-first_subpage.php
<?php
$firstSubPage = perch_pages_navigation([
'from-path' => $_SERVER['REQUEST_URI'],
'levels' => 1,
'template' => 'get_first_subpage.html',
], true);
header('Location: http://'.$_SERVER['SERVER_NAME'].$firstSubPage);
Template: perch/templates/navigation/get_first_subpage.html
<perch:if exists="perch_item_first"><perch:pages id="pagePath" /></perch:if>