Welcome, Guest. Please login or register.
Did you miss your activation email?
May 16, 2012, 09:55:27 PM

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.
155094 Posts in 21661 Topics by 7721 Members
Latest Member: arrow345
* Home Help Search Login Register
Pages: [1]   Go Down
Print
Author Topic: New Breadcrumbs Function as Snippet Module (WB 2.6.1)  (Read 4679 times)
kweitzel
Forum administrator
*****
Offline Offline

Posts: 6974


WWW
« on: February 03, 2006, 10:45:46 AM »

Hi all,

Stefan made a little change to the original breadcrumbs function, requested in the German Board (http://forum.websitebaker.org/index.php/topic,2446.0.html).

The Request:
Quote
Zerosurf wanted to be able to show only from level X to level Y or even a single level Z with the breadcrumbs function.

The Code:

Following Code is what Stefan wrote to answer this request:
Code:
function new_breadcrumbs($sep=' > ',$tier=1,$links=true,$depth=-1) {
   global $wb;
   $page_id=$wb->page_id;
   if ($page_id!=0)
   {
       global $database;
      $bca=$wb->page_trail;
      $counter=0;
      foreach ($bca as $temp)
      {
           if ($counter>=($tier-1) AND ($depth<0 OR $tier+$depth>$counter))
           {
            if ($counter>=$tier) echo $sep;
            $query_menu=$database->query("SELECT menu_title,link FROM ".TABLE_PREFIX."pages WHERE page_id=$temp");
            $page=$query_menu->fetchRow();
            if ($links==true AND $temp!=$page_id)
               echo '<a href="'.page_link($page['link']).'">'.$page['menu_title'].'</a>';
            else
                echo $page['menu_title'];
           }
            $counter++;
      }
   }
}

He added the "$depth" variable to allow for the depth (obvious, isn't it?  grin)


The Usage:

Quote
<?php new_breadcrumbs(' > ',2,true,1);?>

The Variables explained (' > ',2,true,1)
  • ' > ' - defines the spacing character
  • 2 - defines the starting level (can be any number according to the total levels in your pagestructure
  • true - defines if the displayed breadcrumbs are llinked or not linked (false)
  • 1 - defines the depth of the breadcrumps


So, in this case, we do show Breadcrumbs with the ' > ' as spacing, starting from level 2 going to level 3.
Another Example: <?php new_breadcrums(' > ',3,false,0);?> - would only show the level 3 without the links.

You either put the function Code into you template or install and use the attached "snippet module". You could also replace the original breadcrump code in frontend.functions. php (I wouldn't do it, since with any update you would have to replace the code again, if it is not be included ...)

You can check out the whole function on my Website www.weitzel.info/nethome in the section "about us" - "Klaus Weitzel". I used the arguments (' --- ',3,true,1)

cheers

Klaus
Logged

WebsiteBaker Org e.V. - for WebsiteBaker

Isabel

Offline Offline

Posts: 19



« Reply #1 on: February 03, 2006, 01:54:45 PM »

Hi All,

it wasn't exactly obvious to me how this fit in with the old breadcrumbs module that only worked with WB 2.5.  (Klaus and others told me everything I needed to know but they also gave me too many options too tongue)  So, I'm writing to help anyone else who comes across the same difficulty.  As always, these things are obvious once you've worked them out  tongue

For those with WB 2.6, this snippet replaces the previous breadcrumbs module.  To get breadcrumbs on your site, just install the snippet module and then add the
Code:
<?php new_breadcrumbs(' > ',2,true,1);?>
line to your index.php code (in your chosen template).  I added my line just above:
Code:
<?php page_content(); ?>
, which nicely showed my breadcrumbs at the top of every page. 

To be truely honest, I actually added the following to show the home page as well:
Code:
<?php
              
if (PAGE_ID==1)  {
               echo 
'<a href="/index.php">Home </a>';
               } else {
                 echo 
'<a href="/index.php">Home</a> > 'new_breadcrumbs(' > ',1,true,5);
               }
?>


Thanks to Argos http://forum.websitebaker.org/index.php?action=profile;u=153 for the code.

You can find this code and many other options for displaying the breadcrumbs here:
http://forum.websitebaker.org/index.php/topic,731.0.html.  But don't get confused: it was written with v2.5 in mind so not everything will relate directly.

Cheers,

Isabel   
Logged
Zerosurf

Offline Offline

Posts: 25



WWW
« Reply #2 on: February 03, 2006, 02:15:30 PM »

Thx Stefan for helping out with the code!

On this website: http://www.sv-kematen.at you can check it out!

Here is a picture to show how it works:


thx. for everybody else who helped!

Zerosurf
Logged
virgil

Offline Offline

Posts: 177



« Reply #3 on: February 07, 2006, 11:08:14 AM »

@ Isabel


To be truely honest, I actually added the following to show the home page as well:

Code:
<?php
              
if (PAGE_ID==1)  {
               echo '<a href="/index.php">Home </a>';
               } else {
                 echo '<a href="/index.php">Home</a> > 'new_breadcrumbs(' > ',1,true,5);
               }
?>




I'm NOT a php code, so I might be quite wrong, but in order to get your homepage in every case (even) when WB is installed in a sub.directory, wouldn't it be rahter appropriate to modify your code as follows?:


Code:
<?php
              
if (PAGE_ID==1)  {
               echo '<a href="<?php echo WB_URL; ?>
">Home </a>';
               } else {
                 echo '<a href="<?php echo WB_URL?>">Home</a> > '; new_breadcrumbs(' > ',1,true,5);
               }
?>


Just an idea? (hope there is no syntax error)

Cheers,

Virgil

Logged

Virgil - the pre-baked-stuff baker -   wink)
Isabel

Offline Offline

Posts: 19



« Reply #4 on: February 07, 2006, 03:47:34 PM »

Hi Virgil,

'/index.php' should look for index.php in your root directory so it _should_ work on just about all installs.  Unless someone does something tricky like not using '.php' as the file postfix (and Apache may be smart enough to work in that case anyway).  The other benefit is that it doesn't require a database access, which I assume the 'WB_URL;' option does.  (But, 'WB_URL;' is probably cached anyway... so it's probably much of a muchness.)

Still, it is nice to be clear and consistent in one's code; so, despite the above points, I'll agree with you and put 'WB_URL;' in instead.

Thanks for the suggestion,

Isabel

P.S. The whole selection of code is PHP so you don't need those extra tags.  Try the following:
Code:
<?php
              
if (PAGE_ID==1)  {
               echo 
'<a href=".WB_URL;.">Home </a>';
               } else {
                 echo 
'<a href=".WB_URL;.">Home</a> > 'new_breadcrumbs(' > ',1,true,5);
               }
?>

You will see a few full-stops either side of the variable/global.  This is a tricky way of joining items in PHP.  The alternative is to have three echo statements for both those lines.
Logged
Isabel

Offline Offline

Posts: 19



« Reply #5 on: February 23, 2006, 03:52:42 PM »

Hmm,

Oops, made a small mistake below, sorry.  I should have cut and paste directly rather than re-typing it in.  I shouldn't be such a lazy girl Smiley  The mistake for those interested is that I left a semicolon on the end of the WB_URL variable.

Anyway, I made it a bit nicer, while I was at it, by adding in a trailing slash.  Here is the new code:

Quote
<?php
              if (PAGE_ID==1)  {
                 echo '<a href="'.WB_URL.'/">Home </a>';
          } else {
            echo '<a href="'.WB_URL.'/">Home</a> > '; new_breadcrumbs(' > ',1,true,5);
               }
?>

Cheers,

Isabel

P.S. Virgil: your code is probably a bit clearer than my single and double quoting  wink
Logged
virgil

Offline Offline

Posts: 177



« Reply #6 on: February 23, 2006, 06:23:10 PM »

Hi Isabel

P.S. Virgil: your code is probably a bit clearer than my single and double quoting  wink

Well...aehm... the thing is... I don't have an idea why  embarassed ...anyway, it's nice you say that wink

Quote
The mistake for those interested is that I left a semicolon on the end of the WB_URL variable.
Anyway, I made it a bit nicer, while I was at it, by adding in a trailing slash.  Here is the new code:

With me the first version did work fine, I didn't realise any problems without the semicolon left.
Question: what is the 'triling slash' thought to be for? (Is it needed?)

Thx and cheers
Virgil
Logged

Virgil - the pre-baked-stuff baker -   wink)
brofield

Offline Offline

Posts: 224


WWW
« Reply #7 on: February 24, 2006, 06:05:32 AM »

The show_menu2 function can also generate breadcrumbs. See http://forum.websitebaker.org/index.php/topic,2584.0.html for details. A couple of examples are at the demo site.

Cheers,
Brodie
Logged
Isabel

Offline Offline

Posts: 19



« Reply #8 on: February 25, 2006, 12:43:44 PM »

Question: what is the 'triling slash' thought to be for? (Is it needed?)

I'm going to struggle to describe this succinctly but I'll give it a burl  wink

If you go to a URL, your browser looks for files like index.html, index.htm, and index.php.  (These are actually specified in Apache or other web engine.) But, you are looking for an index file in the domain name's root directory, e.g., <www.mydomain.com/index.html>.  This means that when you go to the URL, <www.mydomain.com>, Apache actually needs to redirect you to <www.mydomain.com/>

In the grand scheme of things, it doesn't really matter: you get there in the end and everyone is happy.  But, it does take you a bit longer to get to the site.  It's sort of just the done thing.

The show_menu2 function can also generate breadcrumbs. See http://forum.websitebaker.org/index.php/topic,2584.0.html for details. A couple of examples are at the demo site.

Cheers,
Brodie
Thanks Brodie.

Cheers,

Isabel
Logged
virgil

Offline Offline

Posts: 177



« Reply #9 on: February 25, 2006, 05:55:12 PM »

Shame on me ... embarassed ...

After you explain it... it's so obvious !!!!

Thx & cheers
Virgil
Logged

Virgil - the pre-baked-stuff baker -   wink)
Isabel

Offline Offline

Posts: 19



« Reply #10 on: March 06, 2006, 03:01:52 PM »

Hi All,

Anyone know if there is an option in this module for hidden pages to be hidden in the output of the breadcrumbs?

Cheers,

Isabel
Logged
bumkilla

Offline Offline

Posts: 4


« Reply #11 on: March 21, 2006, 10:14:09 PM »

Hello,
Let me start out saying that every here is doing a very cool job on this. I messed around with Mambo/Joomla for a while until I was told about WB. I've got to say it's a breath of fresh air.

So I wanted the main menu to be Horizontal and the Sub menus to be along the left-hand column and I managed to get all that to work. Then I found this thread and it fixed the other problem I had, which was that there was nothing identifying the page after the first level.

The following isn't really different from the solution provided here, but it has a couple little tweaks. So in the spirit of sharing:

I ended up needing to change the code a little because I didn't want the page identifier to show up on the home page. So I added another if statement to the code that tells it not to show up if the menu_title is "Home". Obviously this only works if your homepage menu button is "Home", but you could change that to fit your needs if it does say something else. Also, make sure that the call within the body of the page has the fourth argument set to "0" otherwise you'll get  too many titles showing up. One more obvious caveat, you'll need to put the code directly into your template and not use the snippet module.

I also changed it so that the indentifier would display as an <h2> element and gave it a class of "page_indentifier" so that it could be modded easily through a style sheet.

Code:
<?php function new_breadcrumbs($sep=' > ',$tier=1,$links=true,$depth=-1) {
   global 
$wb;
   
$page_id=$wb->page_id;
   if (
$page_id!=0)
   {
       global 
$database;
      
$bca=$wb->page_trail;
      
$counter=0;

  foreach ($bca as $temp)
  {
   if ($counter>=($tier-1) AND ($depth<OR $tier+$depth>$counter))
{
if ($counter>=$tier) echo $sep;
$query_menu=$database->query("SELECT menu_title,link FROM ".TABLE_PREFIX."pages WHERE page_id=$temp");
$page=$query_menu->fetchRow();
if ($page['menu_title'] != Home)
{
if ($links==true AND $temp!=$page_id)
   echo '<h2 class="page_identifier"><a href="'.page_link($page['link']).'">'.$page['menu_title'].'</a></h2>';
else
echo '<h2 class="page_identifier">'.$page['menu_title'].'</h2>';
}
}
$counter++;
}
   }

?>

Again, Great job to everyone whose contributed to this CMS.
« Last Edit: March 21, 2006, 10:18:20 PM by bumkilla » 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!