Jump to content


Photo

Breadcrumbs (how-to), and what it says about the system


  • Please log in to reply
30 replies to this topic

#21 Soma

Soma

    Hero Member

  • Moderators
  • 3,188 posts
  • 1745

  • LocationSH, Switzerland

Posted 01 May 2012 - 08:36 AM

You can try something like this:

$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 ? " &gt; " : "";
	echo "</li>";
}

@somartist | modules created | support me, flattr my work flattr.com


#22 onjegolders

onjegolders

    Hero Member

  • Members
  • PipPipPipPipPip
  • 799 posts
  • 207

  • LocationMidlands, UK

Posted 01 May 2012 - 12:42 PM

Thanks Soma, I ended up setting a count variable and a total variable and matching the two.

#23 ryan

ryan

    Hero Member

  • Administrators
  • 5,771 posts
  • 3114

  • LocationAtlanta, GA

Posted 02 May 2012 - 08:51 AM

Another way to do it, just using PHP string functions:

$out = "<ul>";
foreach($parents as $parent) {
    $out .= "<li><a href='{$parent->url}'>{$parent->title}</a></li>!";
}
$out = str_replace('</li>!', '&gt;</li>', rtrim($out, '!')) . '</ul>';


#24 OrganizedFellow

OrganizedFellow

    Full Member

  • Members
  • PipPipPip
  • 97 posts
  • 28

  • LocationEl Paso TX

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 MichaMichaMicha

MichaMichaMicha

    Jr. Member

  • Members
  • PipPip
  • 18 posts
  • 20

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 OrganizedFellow

OrganizedFellow

    Full Member

  • Members
  • PipPipPip
  • 97 posts
  • 28

  • LocationEl Paso TX

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.

 

:D

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 Soma

Soma

    Hero Member

  • Moderators
  • 3,188 posts
  • 1745

  • LocationSH, Switzerland

Posted 06 March 2013 - 12:18 PM

What breadcrumb in the world shows the page your already on?

@somartist | modules created | support me, flattr my work flattr.com


#28 Joss

Joss

    Hero Member

  • Members
  • PipPipPipPipPip
  • 977 posts
  • 667

  • LocationStony Stratford, UK

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>&nbsp;&nbsp;</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 OrganizedFellow

OrganizedFellow

    Full Member

  • Members
  • PipPipPip
  • 97 posts
  • 28

  • LocationEl Paso TX

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 Pete

Pete

    Administrator

  • Administrators
  • 1,756 posts
  • 658

  • LocationChester, England

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 Joss

Joss

    Hero Member

  • Members
  • PipPipPipPipPip
  • 977 posts
  • 667

  • LocationStony Stratford, UK

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