Detecting if the parent is the homepage for sibling menu

So for instance, I built a menu that calls a pages siblings(). The issue the parent is home, I don’t want to show the siblings if the page is one page seperated from the parent. . Any idea how I would do this. So for instance.

Home - Child - Grandchildren

If parent is home don’t so siblings if parent is not show siblings? Anybody ever had to do this. I will be using a checkbox. I just need the logic.

I just don’t know how to work this backwards logic to check if the parent is home? Any help would be awesome.


For example http://localhost:8888 would be the parent or homepage

<?$homePageTest = $page->parent();
if($homePageTest->isHomePage()) : ?>
Do this     
<? else :?>
    something different

But this isn’t working. Not sure why. Thanks

You can use $page->depth() to check the level of the current page and do stuff based on the result.

I think $page->parent() does not work here because normally the homepage doesn’t have children. It’s only the url which suggests it.

http://localhost:8888/ in fact is something like http://localhost:8888/home

The parent of all first level pages (i.e. all subfolders of /content) is the $site object (not the home page):

  home/ //<-- this is the home page

So, home, projects, blog etc. are all siblings on the same level. If the homepage does indeed have subfolders, then these subfolders would be children of the home page, their URL would be http.// Checking if the parent is the home page would only make sense for actual subfolders of home.

1 Like

Any way to make a workaround here? I get some unwanted behaviour of this. So I try having a simple reverse breadcrumb menu using parent()but for the first level it the link works but the title is the $site title not the home title. Any way to avoid this?

I will answer my own question. :slight_smile:

<?php if ($page->depth() == 1): ?>
  <?php if (!$page->isHomePage()): ?>
                    <a href="<?php echo $page->parent()->url() ?>">
                      <i class="icon-arrow-left"></i> Home
  <?php endif ?>
<?php else: ?>
                  <a href="<?php echo $page->parent()->url() ?>">
                    <i class="icon-arrow-left"></i> <?php echo $page->parent()->title()->html() ?>
<?php endif ?>