Welcome, Guest. Please login or register.
Did you miss your activation email?
February 12, 2012, 07:07:04 AM

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
* Home Help Search Login Register
Pages: [1]   Go Down
Print
Author Topic: Code Snippet: Navigation Breadcrumb  (Read 4479 times)
Craig

Offline Offline

Posts: 112



WWW
« 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"&#41;;
if&#40;$query_menu->numRows&#40;&#41; > 0&#41; &#123;
$menu $query_menu->fetchRow&#40;&#41;;
if&#40;$menu['parent'&#93; != 0&#41;&#123;
$level2 $sep '<a href="'.page_link&#40;$menu['link'&#93;&#41;.'" title="'.$menu['page_title'&#93;.'">'.$menu['menu_title'&#93;.'</a>';
$query_level2 $database->query&#40;"SELECT page_id,link,page_title,menu_title FROM ".TABLE_PREFIX."pages WHERE page_id='".$menu['parent'&#93;."' LIMIT 1"&#41;;
$menu $query_level2->fetchRow&#40;&#41;;
$level1 $sep '<a href="'.page_link&#40;$menu['link'&#93;&#41;.'" title="'.$menu['page_title'&#93;.'">'.$menu['menu_title'&#93;.'</a>';
&#125; elseif&#40;$bread['parent'&#93; == 0&#41; &#123;
$level1 $sep '<a href="'.page_link&#40;$menu['link'&#93;&#41;.'" title="'.$menu['page_title'&#93;.'">'.$menu['menu_title'&#93;.'</a>';
&#125;

&#125;
?>

&nbsp;<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  Smiley
Logged

Craig Rodway, IT Support, Bishop Barrington School.
Stefan
Guest
« 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 Offline

Posts: 112



WWW
« Reply #2 on: February 08, 2005, 07:59:04 PM »

Yes, silly me! I've just looked in the 'CsSx' template code and realised! embarassed

Never mind, it was fun trying to do it anyway wink  Trust me giving myself more work than necessary  Tongue
Logged

Craig Rodway, IT Support, Bishop Barrington School.
mightofnight

Offline Offline

Posts: 153


« 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 Cheesy
Logged

-Travis
Craig

Offline Offline

Posts: 112



WWW
« 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 Offline

Posts: 2048



WWW
« 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 Cheesy

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

Website Baker Project Founder
www.websitebaker.or g

To contact me via email, visit:
www.ryandjurovich.c om
wolph

Offline Offline

Posts: 24


WWW
« 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!  Smiley
Logged

Carbonect.com - Building your success online
www.carbonect.com
Stefan
Guest
« 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 Offline

Posts: 24


WWW
« 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
« 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 Offline

Posts: 174


WWW
« 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
« Reply #11 on: February 14, 2005, 08:13:54 PM »

That's what the fix is all about.
Logged
hudge

Offline Offline

Posts: 174


WWW
« 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 Offline

Posts: 8


« 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 Smiley

Thank you
Logged
jerome
Guest
« 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
« 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 Offline

Posts: 25



WWW
« 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
Print
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!