We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Plugin: First Child Redirect

Development and Programming

Mark Croxton's avatar
Mark Croxton
319 posts
16 years ago
Mark Croxton's avatar Mark Croxton

First Child Redirect is a plugin for the Structure module. It allows you to redirect to the first child page of any parent entry in a Structure tree.

Example usage: Unzip the attached plugin file and move it to /system/plugins/

Create a blank template called ‘first_child_redirect’ and enter the tag below in it: {exp:first_child_redirect}

Now you can assign the template to any parent page within your Structure tree, and the page will automatically redirect to it’s first child page. For example:

/about/

Could redirect to:

/about/overview/

Please note that caching should NOT be enabled for the first_child_redirect template.

Compatible with Structure v1.3.1.

EDIT: updated to version 0.5

       
rockthenroll's avatar
rockthenroll
485 posts
16 years ago
rockthenroll's avatar rockthenroll

Great plugin idea Mark! Nice work!

       
Jason Morehead's avatar
Jason Morehead
456 posts
16 years ago
Jason Morehead's avatar Jason Morehead

Thanks so much for making this.

Occasionally, we have clients who don’t want to use the toplevel page that is created in Structure (e.g., “/about/”), but want the first page under “/about/” to be the main page for the “/about/” section. Before, we’ve often had to hard code the navigation to accommodate that request, but this looks like a much better way.

       
Chad Clark's avatar
Chad Clark
20 posts
16 years ago
Chad Clark's avatar Chad Clark

This is exactly what I need. Much better than doing if segment redirects. Thank you!

       
stinhambo's avatar
stinhambo
1,268 posts
16 years ago
stinhambo's avatar stinhambo

We just finished up a site that mimics this but I think I will go back and include this to make support easier.

       
smartpill's avatar
smartpill
456 posts
16 years ago
smartpill's avatar smartpill

This is perfect considering most clients don’t put content in the top level. It does however, assume that the index was removed. Is there a way to check for this and add the index if it’s still there? I suppose I could hard-code it if need be.

       
Mark Croxton's avatar
Mark Croxton
319 posts
16 years ago
Mark Croxton's avatar Mark Croxton
It does however, assume that the index was removed

Aha now I understand - you mean the overview link parameter in the {exp:structure:nav_sub}? I’m not sure it would be possible to check this as it’s hardcoded in the tag in your template.

       
smartpill's avatar
smartpill
456 posts
16 years ago
smartpill's avatar smartpill
It does however, assume that the index was removed
Erm, you’ve lost me there - what index would that be?

Sure. Current site I’m working on with plugin:

http://siteurlhere.com/about/founder/

but actual URL is

http://siteurlhere.com/index.php/about/founder/

I’m no programmer but it looks like your using the “site_url” and then adding the structure path. So “site_index” is ignored.

       
Mark Croxton's avatar
Mark Croxton
319 posts
16 years ago
Mark Croxton's avatar Mark Croxton

I see - you can change line 71 of the plugin to:

header("Location:".$site_url.'/'.$PREFS->ini('site_index').ltrim($first_child_uri,'/'));

Does that work for you?

       
smartpill's avatar
smartpill
456 posts
16 years ago
smartpill's avatar smartpill
I see - you can change line 71 of the plugin to:
header("Location:".$site_url.'/'.$PREFS->ini('site_index').ltrim($first_child_uri,'/'));
Does that work for you?

Really close, missing the slash before the index:

http://siteurlhere.comindex.php/about/founder/

I do have the closing slash in my site url:

http://siteurlhere.com/
       
Mark Croxton's avatar
Mark Croxton
319 posts
16 years ago
Mark Croxton's avatar Mark Croxton

Ok I think I cracked it, could you download this new version and see if it flies?

       
smartpill's avatar
smartpill
456 posts
16 years ago
smartpill's avatar smartpill
Ok I think I cracked it, could you download this new version and see if it flies?

Perfect! Thank you.

       
Mark Croxton's avatar
Mark Croxton
319 posts
16 years ago
Mark Croxton's avatar Mark Croxton

Great stuff. I’ve attached an updated version of the plugin to the first post.

       
mrJones's avatar
mrJones
5 posts
16 years ago
mrJones's avatar mrJones

First of all this plugin really helps as I am always getting clients wanting to contain pages in a section and not realising they have nothing to say on the top level page. All redirects fine.

However when I do a search and click on the resulting links all work fine (I have the correct paths in the settings for the search) except the first child which has the redirect applied. When I click on the link in the search results page it goes to the correct url but the content showing is for the parent container page.

All help much appreciated. Not sure if it is Structure of the redirect plugin.

thanks

Brian

       
Mark Croxton's avatar
Mark Croxton
319 posts
16 years ago
Mark Croxton's avatar Mark Croxton

I’m not sure what the search module does to the urls it generates (not used it yet 😊 ) however a workaround might be to exclude the specific entries that are acting as containers. Give these entries a new status, say “hidden”, and then add status=“not hidden” to your search form tag.

       
1 2

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.