Jump to content

Breadcrumb foreach pagearray error


mrjasongorman
 Share

Recommended Posts

I want to create a basic breadcrumb menu on my site and i'm using this code

<?php $parents = $page->parents(); ?>
<?php foreach( $parents as $item): ?>
  <span><a href='<?php echo $item->url; ?>'><?php echo $item->title; ?></a></span>
<?php endforeach; ?>
<span><?php echo $page->title; ?></span>

When i print_r $page->parents() it has the correct count and urls. But when i go to foreach it misses out a step.

for example if i was on the curriculum page it should say: home > about us > curriculum

but it just echo's out: home > curriculum

Am i doing the foreach wrong? i followed the example code Ryan posted for making a breadcrumb menu.

Link to comment
Share on other sites

This code works perfectly here. Are the pages properly set up hierarchically? (I guess yes)

Where do you have this in code? Does $page refer to the current page?

Link to comment
Share on other sites

Yeah it's strange everything appears to be correct until it actually goes through the foreach loop, then it misses out a page. Hierarchy and everything is correct and when looking at the page array object it's showing the correct number and order of pages.

Link to comment
Share on other sites

  • 2 weeks later...

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