Home
Download
Add-ons
Help
Forum
Organisation
Project
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email?
February 12, 2012, 07:08:05 AM
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Search:
Advanced search
Wollen Sie dem WebsiteBaker Team beitreten?
Nähere Informationen finden Sie unter
hier
und auf unserer
neuen Webseite
.
149621
Posts in
21098
Topics by
7537
Members
Latest Member:
lotte2
WebsiteBaker Community Forum
English
Archive (posts up to 2007)
(Moderator:
Argos
)
Code Snippet: Navigation Breadcrumb
Pages: [
1
]
Go Down
Author
Topic: Code Snippet: Navigation Breadcrumb (Read 4481 times)
Craig
Offline
Posts: 112
Code Snippet: Navigation Breadcrumb
«
on:
February 08, 2005, 06:11:14 PM »
Code:
<?php
// Define separator here
$sep
=
" <strong></strong> "
;
$query_menu
=
$database
->
query
&
#40;"SELECT page_id,parent,link,page_title,menu_title FROM ".TABLE_PREFIX."pages WHERE page_id='".PAGE_ID."' LIMIT 1");
if&
#40;$query_menu->numRows() > 0) {
$menu
=
$query_menu
->
fetchRow
&
#40;);
if&
#40;$menu['parent'] != 0){
$level2
=
$sep
.
'<a href="'
.
page_link
&
#40;$menu['link']).'" title="'.$menu['page_title'].'">'.$menu['menu_title'].'</a>';
$query_level2
=
$database
->
query
&
#40;"SELECT page_id,link,page_title,menu_title FROM ".TABLE_PREFIX."pages WHERE page_id='".$menu['parent']."' LIMIT 1");
$menu
=
$query_level2
->
fetchRow
&
#40;);
$level1
=
$sep
.
'<a href="'
.
page_link
&
#40;$menu['link']).'" title="'.$menu['page_title'].'">'.$menu['menu_title'].'</a>';
&
#125; elseif($bread['parent'] == 0) {
$level1
=
$sep
.
'<a href="'
.
page_link
&
#40;$menu['link']).'" title="'.$menu['page_title'].'">'.$menu['menu_title'].'</a>';
&
#125;
&
#125;
?>
<strong>You are here:</strong> <a href="
<?php
echo
WB_URL
;
?>
">
<?php
echo
WEBSITE_TITLE
;
?>
</a>
<?php
echo
$level1
;
?>
<?php
echo
$level2
;
?>
This code produces a navigation trail like
Your Website -> Section 1 -> Page 4
etc. It suits the Simple template perfectly on the horizontal bar at the top, but could probably be added to just about any template
Logged
Craig Rodway, IT Support, Bishop Barrington School.
Stefan
Guest
Code Snippet: Navigation Breadcrumb
«
Reply #1 on:
February 08, 2005, 07:38:43 PM »
Darn, I should have said it clearer... I had already written a no-level-limit breadcrumb function as well as collapsing/expanding menu. It's included in the templates roundfullcoll.zip and cssbox.zip that can be found on my homepage.
Sorry that you had to redo some work here!
Logged
Craig
Offline
Posts: 112
Code Snippet: Navigation Breadcrumb
«
Reply #2 on:
February 08, 2005, 07:59:04 PM »
Yes, silly me! I've just looked in the 'CsSx' template code and realised!
Never mind, it was fun trying to do it anyway
Trust me giving myself more work than necessary
Logged
Craig Rodway, IT Support, Bishop Barrington School.
mightofnight
Offline
Posts: 153
Code Snippet: Navigation Breadcrumb
«
Reply #3 on:
February 09, 2005, 12:35:07 AM »
Neat I hope to shortly see this and some of the other things i have seen around the board in the code sniplets section soon
Logged
-Travis
Craig
Offline
Posts: 112
Code Snippet: Navigation Breadcrumb
«
Reply #4 on:
February 09, 2005, 12:47:20 AM »
Just for reference, here is the one by Stefan:
Quote
To have breadcrumbs like this:
top > sublevel 1 > sublevel 2
call breadcrumbs() with breadcrumbs(PAGE_ID," > ")
$start denotes the first level displayed,
usually 0 (top-level)
Code:
function breadcrumbs($page_id,$sep)
{
global $database;
global $bca;
if (sizeof($bca)==0)
create_breadcrumbs($page_id);
$counter=0;
foreach ($bca as $temp)
{
if ($counter>1)
echo $sep;
$query_menu=$database->query("SELECT menu_title FROM ".TABLE_PREFIX."pages WHERE page_id=$temp");
$page=$query_menu->fetchRow();
echo $page['menu_title'];
$counter++;
}
}
function create_breadcrumbs($item)
{
global $database;
global $bca;
$query_menu=$database->query("SELECT page_id,parent FROM ".TABLE_PREFIX."pages WHERE page_id = '$item'");
$page=$query_menu->fetchRow();
if ($page['parent']!=0)
create_breadcrumbs($page['parent']);
else $bca[]='0';
$bca[]=$page['page_id'];
}
Logged
Craig Rodway, IT Support, Bishop Barrington School.
Ryan
Offline
Posts: 2048
Code Snippet: Navigation Breadcrumb
«
Reply #5 on:
February 09, 2005, 06:44:25 AM »
Quote from: mightofnight
Neat I hope to shortly see this and some of the other things i have seen around the board in the code sniplets section soon
- Well, once the community site is set-up, you will be able to help administer the site yourself! However, I am too busy to do such things at the moment, but my time should be free in about 2 weeks.
Logged
Website Baker Project Founder
www.websitebaker.or
g
To contact me via email, visit:
www.ryandjurovich.c
om
wolph
Offline
Posts: 24
Code Snippet: Navigation Breadcrumb
«
Reply #6 on:
February 11, 2005, 09:09:41 AM »
I was running into some problems when I tried to access a page that did not have an id greater than 0 (i.e. if the page was not in the CMS db) so I made some changes to Stefan's script to fix that and I decided to post it here so others who may need it can use it.
This is the 'slightly modified' set of functions
Code:
/**
* This is a set of functions that generate the "bread crumbs" for a given page.
* These functions were created by Stefan I only modified them slightly to fix a minor quirk.
* All changes have been documented, credit should still be given to Stefan as the original creator.
*
* @category
WebsiteBaker - Helper Script
* @package
Bread Crumb Generator
* @author Stefan <> | Original author
* @author Wolph <>
*
* @param array $params The parameters to set the properties
* @access public
* @return string
*/
// {{{ Bread Crumbs block
function breadcrumbs($page_id,$sep)
{
// do a check of the passed in value, if this is not
// a 'valid' page for WB to handle, puke it out!
if ($page_id == 0) {return false;}
$crumbs = ''; // prepare the string to return
global $database;
global $bca;
if (sizeof($bca)==0)
create_breadcrumbs($page_id);
$counter=0;
foreach ($bca as $temp)
{
if ($counter>1)
$crumbs.= $sep;
// append to the return string
$query_menu=$database->query("SELECT menu_title FROM ".TABLE_PREFIX."pages WHERE page_id=$temp");
$page=$query_menu->fetchRow();
$crumbs.= $page['menu_title']; // append to the return string
$counter++;
}
return $crumbs; // return the crumbs for whatever use
}
/**
* Helper function in Bread Crumb Generator
*/
function create_breadcrumbs($item)
{
global $database;
global $bca;
$query_menu=$database->query("SELECT page_id,parent FROM ".TABLE_PREFIX."pages WHERE page_id = '$item'");
$page=$query_menu->fetchRow();
if ($page['parent']!=0)
create_breadcrumbs($page['parent']);
else $bca[]='0';
$bca[]=$page['page_id'];
}
// }}}
Please note that there is also a slight (but essential) usage modification:
Instead of
Quote
To have breadcrumbs like this:
top > sublevel 1 > sublevel 2
call breadcrumbs() with breadcrumbs(PAGE_ID," > ")
You must call breadcrumbs()
Quote
with
echo
breadcrumbs(PAGE_ID," > ")
This is because one of the modifications is to let bread crumbs "cache" it's results in a string and then it returns that string. I just think this allows some level of flexibility in using the crumbs; i.e. they dont necessarily have to be shown where the function is called.
Hope this is worth a penny!
Logged
Carbonect.com - Building your success online
www.carbonect.com
Stefan
Guest
Code Snippet: Navigation Breadcrumb
«
Reply #7 on:
February 11, 2005, 01:58:39 PM »
Thanks for the fix. There already exists an advanced version with more flexibility that can be downloaded from my website. I will include your fix there.
Logged
wolph
Offline
Posts: 24
Code Snippet: Navigation Breadcrumb
«
Reply #8 on:
February 11, 2005, 05:53:52 PM »
Great stuff Stefan, let me know once you've incorporated the fix -- I'll much rather use and advanced one any time!
Logged
Carbonect.com - Building your success online
www.carbonect.com
Stefan
Guest
Code Snippet: Navigation Breadcrumb
«
Reply #9 on:
February 11, 2005, 07:00:38 PM »
It already happened. Didn't include your echo change though. If you can tell me a good reason, why one would ever need to call and to echo in different places, I will gladly implement it.
Logged
hudge
Offline
Posts: 174
Code Snippet: Navigation Breadcrumb
«
Reply #10 on:
February 14, 2005, 08:12:54 PM »
I relized I have an error on my search page with the breadcrumb. Please check yours too and post if yours works. thanks.
Logged
: Member of the Baker's Dozen :
Baking at 350˚ for 2 hours now...
Stefan
Guest
Code Snippet: Navigation Breadcrumb
«
Reply #11 on:
February 14, 2005, 08:13:54 PM »
That's what the fix is all about.
Logged
hudge
Offline
Posts: 174
Code Snippet: Navigation Breadcrumb
«
Reply #12 on:
February 14, 2005, 08:16:57 PM »
opps...my bad stefan thanks for a rapid reply.
Logged
: Member of the Baker's Dozen :
Baking at 350˚ for 2 hours now...
Kweli
Offline
Posts: 8
Code Snippet: Navigation Breadcrumb
«
Reply #13 on:
July 12, 2005, 03:22:51 PM »
@wolph:
This is really cool. But:
Craig's Version has links, your version only has text only. Is it possible to build this as a list of links? Because otherwise there's no sense in that in my opinion
Thank you
Logged
jerome
Guest
Code Snippet: Navigation Breadcrumb
«
Reply #14 on:
July 15, 2005, 06:19:17 PM »
there's something I don't understand in Stefan's Bread Crumbs.
When I look at the generated code of
http://stefan-braunewell.de
with a template using Bread Crumbs, I find this :
<a href="
http://stefan-braunewell.de/wb/pages.php
"></a>
I think it's bad for google to index error page.
Logged
Stefan
Guest
Re: Code Snippet: Navigation Breadcrumb
«
Reply #15 on:
August 09, 2005, 10:53:04 AM »
@jerome
I don't understand - sounds like you get an error using one of the templates in the showcase?! I can't find anything...
Logged
Zerosurf
Offline
Posts: 25
Re: Code Snippet: Navigation Breadcrumb
«
Reply #16 on:
January 19, 2006, 09:54:27 AM »
1. Question:
If I wanna start from the 2. Level
Code:
<?php breadcrumbs
(
PAGE_ID
,
' > '
,
2
);
?>
then the 1. Level still is showing up together with the 2. Level NOT separeted!
Is that on purpose - or a bug?
2. Question:
Is it possible to stop at a certain level?
For Example:
I have 5 Levels and I just want to show the breadcrumbs from Level 2 to 4, even if I am in the 5th Level!
Or I just want to show only one Level - for example Level 3!
Is that possible?
Thx.i.a.
Zerosurf
«
Last Edit: January 29, 2006, 02:38:24 PM by Zerosurf
»
Logged
Pages: [
1
]
Go Up
Jump to:
Please select a destination:
-----------------------------
General
-----------------------------
=> General Announcements
-----------------------------
English
-----------------------------
=> Help & Support
-----------------------------
General
-----------------------------
=> WebsiteBaker Website Showcase
-----------------------------
English
-----------------------------
=> Modules
=> Templates, Menus & Design
=> WebsiteBaker Language Files
=> Droplets (PHP code for use with Droplet module) & Snippets (raw PHP code)
-----------------------------
General
-----------------------------
=> Guest Area & Off-Topic
-----------------------------
English
-----------------------------
=> WebsiteBaker 2.x discussion
=> WebsiteBaker 3
-----------------------------
General
-----------------------------
=> Security Announcements
-----------------------------
Deutsch (German)
-----------------------------
=> Hilfe/Support
-----------------------------
General
-----------------------------
=> Documentation
-----------------------------
Francais (French)
-----------------------------
=> Help/Support
-----------------------------
Italiano (Italian)
-----------------------------
=> Help/Support
-----------------------------
Deutsch (German)
-----------------------------
=> Ankündigungen
=> Diskussion über WB
=> Off-Topic
=> Archiv für Themen bis 2007
=> Module & Snippets
-----------------------------
English
-----------------------------
=> Archive (posts up to 2007)
-----------------------------
Nederlands (Dutch)
-----------------------------
=> Aankondigingen
=> Hulp & Ondersteuning
=> Niet-Terzake (Off Topic)
-----------------------------
Deutsch (German)
-----------------------------
=> jQuery
=> Tutorials
=> Templates & Design
-----------------------------
English
-----------------------------
=> jQuery
-----------------------------
Bakery (WB shop module)
-----------------------------
=> Bakery English
=> Bakery Deutsch
-----------------------------
English
-----------------------------
=> WebsiteBaker 2.9
===> Announcements
===> Help/Support
===> Suggestions
-----------------------------
Deutsch (German)
-----------------------------
=> WebsiteBaker 2.9
===> Ankündigungen
===> Hilfe/Support
===> Vorschläge
-----------------------------
English
-----------------------------
===> Software bugs
-----------------------------
Deutsch (German)
-----------------------------
===> Softwarefehler
=====> Module / Extensions
-----------------------------
English
-----------------------------
=====> Modules / Extensions
-----------------------------
Deutsch (German)
-----------------------------
===> Erfahrungs und Testberichte
-----------------------------
KeepInTouch (Multi Contact Module)
-----------------------------
=> KeepInTouch English
=> KeepInTouch Deutsch
Loading...