Jump to content

How do you handle intermediate sub-page ?


Doc
 Share

Recommended Posts

Hi,

I'm building new categories below the homepage, such as :

home
    /cycle
        /race
        /city
    /motorbike
        /roadsters
        /sports

How do you handle what's going on if a user hits /home/cycle only ? I have nothing to show here.

For now I've associated /cycle with the 'basic-page' template...

Do I have to redirect to the first sub-page such as /home/cycle/race for example ? or do you redirect to /home in such a case ?

Thanks

Link to comment
Share on other sites

If you have a header with a navbar or just a navbar this code works for me:

<?php
	$rootPage = wire('pages')->get('/');
	$children = $rootPage->children();
	foreach ($children as $child)
	{
		echo "<li>";
		$grandchildren = $child->children();
		if(count($grandchildren)){
			echo "<span class='pseudo_anchor noselect'>{$child->title}</span>";
			echo "<ul class='dropdown_menu'>";
			foreach ($grandchildren as $grandchild){
				echo "<li><a href='{$grandchild->url}'>{$grandchild->title}</a></li>";
			}
			echo "</ul>";
		}
		else echo "<a class='noselect' href='{$child->url}'>{$child->title}</a>";
		echo "</li>";
	}
?>

This code checks if the childpage has children. If the child has children then the it will be only a span with the child->title. But if it doesn't have children then the url will be active and you can click on it.

Link to comment
Share on other sites

Thanks Harmen,

I can borrow some part of your code for future manipulation within the childen categories.

Actually I have a header with a menu which displays all the children pages, hardcoded, I want them all displayed at once. So I don't have to navigate here.

Links are for example :

website.com/cycle/race -> show a list of that categories

website.com/motorbike/roadsters -> show a list of that categories

I was wondering myself how to handle the case where a user doesn't click on a link but directly go to website.com/cycle for example, and how to deal with that.

I guess I can use your code to detect if /cycle has children page, if yes, display the first one for example, otherwise redirect to the homepage.

Link to comment
Share on other sites

Hi Doc,

Glad you can use it. I get your point and I think you are right with this:

3 minutes ago, Doc said:

I guess I can use your code to detect if /cycle has children page, if yes, display the first one for example, otherwise redirect to the homepage.

Maybe you could redirect directly to the first child page or display the 404 page and redirect to the homepage within 2 or 3 seconds automatically.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...