$parents = $page->parents->slice(2);
foreach($parents as $parent) {
echo "<li><a href='{$parent->url}'>{$parent->title}</a>";
// only output ">" if not the last entry
echo $parent->id != $parents->last()->id ? " > " : "";
echo "</li>";
}
Breadcrumbs (how-to), and what it says about the system
#21
Posted 01 May 2012 - 08:36 AM
@somartist | modules created | support me, flattr my work flattr.com
#24
Posted 05 March 2013 - 08:14 PM
Lets say that you also wanted to include the current page in your breadcrumb trail (which is probably redundant, but some sites do it). What you'd do is just append it to the list of parents that gets cycled through:
<?php foreach($page->parents()->append($page) as $parent) { echo "<a href='{$parent->url}'>{$parent->title}</a> "; }
Hi Ryan.
I'm using the above and can't figure out how to style the current page.
<ul class="breadcrumbs"> <li><a href="#">Home</a></li> <li><a href="#">Page1</a></li> <li><a href="#">Page2</a></li> <li class="current"><a href="#">Page3</a></li> </ul>
How would I style the current page?
This is what I have right now:
echo "<ul class=\"breadcrumbs\">";
foreach($page->parents() ->append($page) as $parent)
echo "<li><a href='{$parent->url}'>{$parent->title}</a></li>";
echo "</ul>";
Edited by OrganizedFellow, 05 March 2013 - 09:24 PM.
#25
Posted 06 March 2013 - 06:29 AM
Hi Ryan.
I'm using the above and can't figure out how to style the current page.
<ul class="breadcrumbs"> <li><a href="#">Home</a></li> <li><a href="#">Page1</a></li> <li><a href="#">Page2</a></li> <li class="current"><a href="#">Page3</a></li> </ul>
How would I style the current page?
This is what I have right now:
echo "<ul class=\"breadcrumbs\">"; foreach($page->parents() ->append($page) as $parent) echo "<li><a href='{$parent->url}'>{$parent->title}</a></li>"; echo "</ul>";
echo "<ul class=\"breadcrumbs\">";
foreach($page->parents() ->append($page) as $parent)
echo "<li".($parent == $page?" class='current'":"")."><a href='{$parent->url}'>{$parent->title}</a></li>";
echo "</ul>";
This should do the trick, if that's what you're looking for.
Note: not tested for syntax-errors, typed it directly in the commentarea.
#26
Posted 06 March 2013 - 12:16 PM
This should do the trick, if that's what you're looking for.
Note: not tested for syntax-errors, typed it directly in the commentarea.
![]()
Awesome.
I was trying to figure out HOW it works (my PHP skills are at beginner level). And I understand it ![]()
".($parent == $page?" class='current'":"")."
So that's kinda like saying, if the page is the current page, put this class.
#27
Posted 06 March 2013 - 12:18 PM
@somartist | modules created | support me, flattr my work flattr.com
#28
Posted 06 March 2013 - 12:30 PM
Mine do!
If possible I like to surround it with bouncing ball, flashing arrows and a horde of Angels singing "We'll meet again"
Oh, and I tend not to have it linked .... ![]()
This is one for Bootstrap classes.
(I have left off the dancing chihuahuas)
<ul class='breadcrumb'>
<?php
echo "<li><a href='{$pages->get("/")->url}'><i class='icon-home'></i></a> </li>";
foreach($page->parents as $parent) {
echo "<li><a href='{$parent->url}'>{$parent->title}</a> <span class='divider'>/</span></li>";
}
echo "<li class='active'>{$page->title}</li>";
?>
</ul>
Be nice - I am not a proper programmer and haven't the foggiest idea of what Soma/Apeisa/Ryan/et al are talking about.
Website Dev: http://www.stonywebsites.co.uk
Music Composition: http://www.dancingbear.co.uk
Writing: http://www.sanglier.co.uk
#29
Posted 06 March 2013 - 01:16 PM
What breadcrumb in the world shows the page your already on?
I'm using Foundation4. Check out this little code snippet they have.
http://foundation.zu...readcrumbs.html
I'm just learning to use ProcessWire, as I've been trolling here for a long time. I haven't actually used it for a site yet.
So I'm collecting all the snippets I need to use all my favorite elements and components from Foundation.
#30
Posted 07 March 2013 - 07:42 AM
I do have a habit on a couple of sites of having the current page added to the breadcrumb but without a link. It just feels more complete to me.
If it sounds odd, go back to the fairy tale and assume that the current page without a link is the spot you're standing on without dropping any breadcrumbs. "You are here, in case you didn't know and don't see the title in an obvious location on the page" can actually be relevant if you arrive at a page from search results for example, but I think it's more about personal tastes than anything else.
#31
Posted 07 March 2013 - 09:01 AM
I look at it like a line of obedient hounds following a trail of tasty morsels.
When they get to where you are currently standing, they all sit there looking at you with big, expectant, eyes, waiting for you to drop something.
Be nice - I am not a proper programmer and haven't the foggiest idea of what Soma/Apeisa/Ryan/et al are talking about.
Website Dev: http://www.stonywebsites.co.uk
Music Composition: http://www.dancingbear.co.uk
Writing: http://www.sanglier.co.uk
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users













