Breadcrumb
Permalink
Any suggestions as to the best way to show a breadcrumb to let users know where they are within the navigation. Preferably in a format that looks something like this:
Top Page > Sub Page > Sub-sub page
Top Page > Sub Page > Sub-sub page
Here's what I came up with...
Couple of notes...the array actually has to be sorted using krsort in order to display the pages in the proper order (top first).
Also, this doesn't display the current page, so code needs to be added for that. Here's the adjusted code
Also, this doesn't display the current page, so code needs to be added for that. Here's the adjusted code
For some reason the code printed above works in FF but not in IE or Google Chrome. I'm getting this error:
Fatal error: Class 'NavigationHelper' not found in /srv/www/htdocs/concrete/themes/mc/one_column.php on line 211
Any thoughts?
Fatal error: Class 'NavigationHelper' not found in /srv/www/htdocs/concrete/themes/mc/one_column.php on line 211
Any thoughts?
Forgive me again. I was logged in in Firefox but not IE...that was why it worked in FF. Is there a way to get this code working for a non-authenticated user?
replace jgarcia's code, "$nh = new NavigationHelper(); " -> "$nh = Loader::helper('navigation');".
it work whenever user is login or not.
here is full code.
it work whenever user is login or not.
here is full code.
function show_breadcrumb($c) { $nh = Loader::helper('navigation'); $breadcrumb = $nh->getTrailToCollection($c); krsort($breadcrumb); foreach ($breadcrumb as $bcpage) { echo '<a href="' . $bcpage->getCollectionPath() . '/">' . $bcpage->getCollectionName() . '</a> > '; } echo $c->getCollectionName(); } // output show_breadcrumb($c);
Would it be possible to add this feature in the next version of C5?
Because I really can't not do what your talking about. I'm surely not the only one, no?
Thanks.
Because I really can't not do what your talking about. I'm surely not the only one, no?
Thanks.
I've just had a play with this. Combining the work of smilkobuta (post above) and the text below from the pagehttp://www.concrete5.org/help/documentation/developers/understandin...
I came up with the file breadcrumbs.php
The documentation page says:
Let's say you want to create a new template for your autonav block. The built-in autonav template is mostly fine, but you want a "breadcrumb" template as well. In your local blocks/ directory (which is typically empty when you install Concrete5), create
autonav/templates/breadcrumb.php
Paste the code from concrete/blocks/autonav/view.php into this file, and then modify as necessary. Then, when you wish to use this template, click on the block you'd like to modify, and select "Choose Custom Template" from the menu. Your "Breadcrumb" template should appear in the select menu.
The file breadcrumbs.php modified from the view.php file which I used was:
This uses the function that smilkobuta detailed with a minor modification: I added BASE_URL.DIR_REL to the link which is created, so that it worked in my install which is in a sub directory. Also, for it to work properly you need to have pretty_urls selected in the sitewide settings. Otherwise, you have to include index.php also in the url which is generated in the breadcrumbs file for it to work.
Finally, to use it, you install an autonav block, and then click on the installed block and choose the custom template file breadcrumbs.php (which you have just installed) to activate it.
Hope this makes it a bit clearer how you can implement a breadcrumb autonav.
I came up with the file breadcrumbs.php
The documentation page says:
Let's say you want to create a new template for your autonav block. The built-in autonav template is mostly fine, but you want a "breadcrumb" template as well. In your local blocks/ directory (which is typically empty when you install Concrete5), create
autonav/templates/breadcrumb.php
Paste the code from concrete/blocks/autonav/view.php into this file, and then modify as necessary. Then, when you wish to use this template, click on the block you'd like to modify, and select "Choose Custom Template" from the menu. Your "Breadcrumb" template should appear in the select menu.
The file breadcrumbs.php modified from the view.php file which I used was:
<?php defined('C5_EXECUTE') or die(_("Access Denied.")); $aBlocks = $controller->generateNav(); global $c; //output show_breadcrumb($c); function show_breadcrumb($c){ $nh=Loader::helper('navigation'); $breadcrumb=$nh->getTrailToCollection($c); krsort($breadcrumb); foreach($breadcrumb as $bcpage){ echo'<a href="'.BASE_URL.DIR_REL.$bcpage->getCollectionPath().'/">'.$bcpage->getCollectionName().'</a>>'; } echo$c->getCollectionName(); }
Viewing 15 lines of 16 lines. View entire code block.
This uses the function that smilkobuta detailed with a minor modification: I added BASE_URL.DIR_REL to the link which is created, so that it worked in my install which is in a sub directory. Also, for it to work properly you need to have pretty_urls selected in the sitewide settings. Otherwise, you have to include index.php also in the url which is generated in the breadcrumbs file for it to work.
Finally, to use it, you install an autonav block, and then click on the installed block and choose the custom template file breadcrumbs.php (which you have just installed) to activate it.
Hope this makes it a bit clearer how you can implement a breadcrumb autonav.
My breadcrumb is viewing but its not showing the second level items as it should. I have a top level header nav area with my parent items - when you click on News/Events it comes up with a secondary breadcrumb underneath with News item 1, 2 and 3 etc.
Although in the preview its showing news item 1, news item 2, news item 3 when I change the template to breadcrumb it defaults back to the top level home > news/events in the breadcrumb. These are parent levels.
It seems to order fine when I use the header nav template but I want to use the breadcrumb template. What am I doing wrong any ideas??
Although in the preview its showing news item 1, news item 2, news item 3 when I change the template to breadcrumb it defaults back to the top level home > news/events in the breadcrumb. These are parent levels.
It seems to order fine when I use the header nav template but I want to use the breadcrumb template. What am I doing wrong any ideas??
I just wanted to say thanks for sharing the code.
I actually put this on my template and shows the breadcrumb nicely without having to add any extra blocks. =)
I actually put this on my template and shows the breadcrumb nicely without having to add any extra blocks. =)
This code doesn't work when comparing versions - I get the following error when I try:
Any thoughts?
Fatal error: Cannot redeclare show_breadcrumb() (previously declared in /c5/themes/SLC/default.php:72) in /c5/themes/SLC/default.php on line 80
Any thoughts?
Is it possible to modify this so that the breadcrumb list does not include the top level/menu item of the site?
I have this main navigation:
- Home
- Technologies
* Technologies subpage 1
* Technologies subpage 2
* Technologies subpage 3
- Mainmenuitem 3
- Mainmenuitem 4
Currently the crumbs displays as:
Home / Technologies / Technologies subpage 1 / Technologies subpage 2
I want it to just be:
Technologies / Technologies subpage 1 / Technologies subpage
I'm really only skilled in html and css, php is new ground for me, tried a couple of things that resulted in fatal errors.
Any help would be greatly appreciated.
I have this main navigation:
- Home
- Technologies
* Technologies subpage 1
* Technologies subpage 2
* Technologies subpage 3
- Mainmenuitem 3
- Mainmenuitem 4
Currently the crumbs displays as:
Home / Technologies / Technologies subpage 1 / Technologies subpage 2
I want it to just be:
Technologies / Technologies subpage 1 / Technologies subpage
I'm really only skilled in html and css, php is new ground for me, tried a couple of things that resulted in fatal errors.
Any help would be greatly appreciated.
How are you showing the breadcrumbs? Is it with the autonav block (using the "breadcrumb" custom template)? If so, you can customize the breadcrumb template by doing the following:
* Create a new directory on your server at SITEROOT/blocks/autonav/templates
* Copy the file SITEROOT/concrete/blocks/autonav/templates/breadcrumb.php to the new directory you created above, so the new copy is SITEROOT/blocks/autonav/templates/breadcrumb.php
* Edit the new copy of the file, find this line:
...and directly below it, add this new line:
* Create a new directory on your server at SITEROOT/blocks/autonav/templates
* Copy the file SITEROOT/concrete/blocks/autonav/templates/breadcrumb.php to the new directory you created above, so the new copy is SITEROOT/blocks/autonav/templates/breadcrumb.php
* Edit the new copy of the file, find this line:
$_c = $ni->getCollectionObject();
...and directly below it, add this new line:
if ($_c->getCollectionID() == HOME_CID) { continue; } //skip home page
Thanks heaps! This worked like a charm.
I used it on the breadcrumb.php file that came installed with concrete5 though, and not the one listed as code further up, that one didn't work.
I used it on the breadcrumb.php file that came installed with concrete5 though, and not the one listed as code further up, that one didn't work.
I have the breadcrumbs working just fine, but I'd like to add a visual separator between the links. It would be nice to have the option of specifying either a character or an image to use as the separator. Thus:
link > link > link
Right now I just have it thus:
link link link
link > link > link
Right now I just have it thus:
link link link
Well you can change it quite easily in the code
contains the separator (the >)
You could for example use a - by using - here instead of the >
An image could be used used by changing this line to:
and including a suitable graphic file (like the one attached) into blocks/autonav/templates
It is a bit of a mess as the code lines don't wrap above, but I attach the complete breadcrumbs.php file I use also. (saved as breadcrumbs.txt)
echo'<a href="'.BASE_URL.DIR_REL.$bcpage->getCollectionPath().'/">'.$bcpage->getCollectionName().'</a>>';
You could for example use a - by using - here instead of the >
An image could be used used by changing this line to:
echo'<a href="'.BASE_URL.DIR_REL.$bcpage->getCollectionPath().'/">'.$bcpage->getCollectionName().'</a><img src="'.BASE_URL.DIR_REL.'/blocks/autonav/templates/myseparator.jpg" alt="separator" />';
and including a suitable graphic file (like the one attached) into blocks/autonav/templates
It is a bit of a mess as the code lines don't wrap above, but I attach the complete breadcrumbs.php file I use also. (saved as breadcrumbs.txt)
You don't need to create a block... well, maybe not... just use CSS to create a breadcrumb. Use Concrete5's autonav for the breadcrumb, and style the UL and LI stylesheet appropriately. You can find tutorials on this... just search google.
do you have a sample of a working CSS breadcrumb? I would love to see it
I am hoping someone can help some more with the CSS. I've been searching all over and while I have found code that will display and flatten out the UL list, it does NOT flatten out when a child UL list is displayed.
In my site I have several pages "nested" inside folders to group them together and then the "sub" pages are listed on a 2nd line in the bread crumb.
Right now the CSS I am using is (below) like I said this works great for the first tier but not subsequent ones - ideas????
#page .bread ul li {
display:inline;
list-style:none;
font-size: 12px;
margin-bottom: 10px;
padding-top: 2px;
padding-bottom: 10;
padding-left: 10px;
margin-top: 10px;
padding-right:10px; /*width of img + a bit*/
}
#page .bread li:after {
margin-left: 3px;
margin-right: 3px;
content: "/";
}
#page .bread li:last-child:after {
content: "";
padding-right:none;
}
In my site I have several pages "nested" inside folders to group them together and then the "sub" pages are listed on a 2nd line in the bread crumb.
Right now the CSS I am using is (below) like I said this works great for the first tier but not subsequent ones - ideas????
#page .bread ul li {
display:inline;
list-style:none;
font-size: 12px;
margin-bottom: 10px;
padding-top: 2px;
padding-bottom: 10;
padding-left: 10px;
margin-top: 10px;
padding-right:10px; /*width of img + a bit*/
}
#page .bread li:after {
margin-left: 3px;
margin-right: 3px;
content: "/";
}
#page .bread li:last-child:after {
content: "";
padding-right:none;
}
Thanks for this.
The bread crumb is showing up well.
The problem I am having is for pages with show next link checked.
eg. Ministries is the parent but when clicked goes directly to the first child page.
Using breadcrumbs it goes to the parent page and not the first child like it should.
I'd be grateful for any suggestions or extension to this snippet.
The bread crumb is showing up well.
The problem I am having is for pages with show next link checked.
eg. Ministries is the parent but when clicked goes directly to the first child page.
Using breadcrumbs it goes to the parent page and not the first child like it should.
I'd be grateful for any suggestions or extension to this snippet.
Version 5.7 (display breadcrumb in code:)
$autonav = BlockType::getByHandle('autonav'); $autonav->controller->orderBy = 'display_asc'; $autonav->controller->displayPages = 'all'; $autonav->controller->displaySubPages = 'relevant_breadcrumb'; $autonav->controller->displaySubPageLevels = 'all'; $autonav->render('templates/breadcrumb');