Forum

Thread tagged as: Discussion

Tip: Redirect to first subpage

I'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.

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);

perch/templates/navigation/get_first_subpage.html

<perch:if exists="perch_item_first"><perch:pages id="pagePath" /></perch:if>
Shane Lenzen

Shane Lenzen 18 points

  • 1 year ago

Fancy! Thanks Shane. I'll be using that.

Jonathan Elliman said:

Fancy! Thanks Shane. I'll be using that.

Nice! Happy it will help.

very cool!