WP Create Page-Group Holders
WordPress really does have a vast use, people use it daily to create dynamic CMS site and not just as a blog engine however it doesnt come without a lot of headaches for the developer trying to bring the full CMS feel.
One headache I encountered recently was when trying to setup a parent folder redirect structure to a site, The parent folder wanted to always redirect to the first child page, but retain the folder structure. There is no way by default to set up a group holder house all the child feature pages
The desired result I needed to achive was to have a structure like the following:
- Landing Page(redirect to Child1)
- Child1
- Child2
- Child3
This structure would produce pages to be categorised without the need of having to navigate to a landing page then a link to the 1st desired feature page.
To achieve the desired result I had to create a new template that the user would hit then be redirect on to the first child page, this can be eaisly achieved by just using the wp_redirect() function.
The code I used for the template is as followed:
<?php
/*
Template Name: Features Landing
*/
ob_start();
$childPages= get_pages("child_of=".$post->ID."&sort_column=menu_order");
if ($childPages) {
$firstchild = $childPages[0];
// Tells the browser that it is a permanently redirected
//to the child page and redirects
wp_redirect(get_permalink($firstchild->ID),301);
}
//Stops PHP complaining that headers have already been sent.
ob_end_flush();
?>
And that's all you need for to set up a group page holder in WordPress.
I'm always happy to hear new a better ways to achieve a much more efficient process, so I'm happy to hear your improvements.
Thanks
Matt


A budding Web Developer and Tech Geek