General
Getting & Giving Support
Administration
Design
- Tut. - Layouts and Themes
- Tut. - Navigation cookbook
- Tut. - How To section
Reference Material
Plugin Development
- Tut. - Writing a plugin
- Ref. - List of Events
- Ref. - Enabling cron jobs
- Ref. - PHPDoc
Core Development
- Ref. - PHPDoc
Press information
Wolf CMS books section
Using Breadcrumbs in the Site Title
Introduction
There are many different approaches to using the site <title> . . . </title> tags to display page information in the browser frame.1)
Often it is used almost as a type of ”breadcrumbs”, giving the trail of pages after the site title:
Website Name :: Music :: Baroque :: Bach
It is fairly easy to use Wolf's “breadcrumbs” to do this, although it requires some adjustments: the “Home” reference needs to be removed, and the links stripped.
Code
Use this code to produce a <title> arrangement like the one above:
<?php $bcs = strip_tags($this->breadcrumbs('/')); $listBcs = explode(' / ', $bcs); foreach ($listBcs as $key => $val) { if ($key != 0) { echo " :: $val"; } else { echo "Website Name"; } } ?>
If you want to give a different separator between the Website Name and the rest of the page titles, use this variation:
<?php $bcs = strip_tags($this->breadcrumbs('/')); $listBcs = explode(' / ', $bcs); foreach ($listBcs as $key => $val) { if ($key >= 2) { echo " › $val"; } elseif ($key == 1) { echo " » $val"; } else { echo "Website Name"; } } ?>
This will give you a title line in this form:
Website Name » Music › Baroque › Bach
If you prefer to have the current page first, and the “Website Name” last,2) you can reverse the breadcrumbs this way by using the krsort3) function on the “$listBcs” array:
<?php $bcs = strip_tags($this->breadcrumbs('/')); $listBcs = explode(' / ', $bcs); krsort($listBcs); foreach ($listBcs as $key => $val) { if ($key >= 2) { echo "$val ‹ "; } elseif ($key == 1) { echo "$val « "; } else { echo "Website Name"; } } ?>
This gives the result:
Bach ‹ Baroque ‹ Music « Website Name
Usage notes
- don't forget to change “Website Name” to the real name of your site;
- when on the homepage, the code above will give the “Website Name” without any separators;
- use different separators by changing the symbols found in the in echo ”
$val <”; type statements, above; - this is a good candidate to be used as a snippet; simply create the snippet, as e.g., “siteTitle”, then use it in the layout like this:
<title><?php $this->includeSnippet('siteTitle'); ?></title>
Alternate Code
[From “gavsiu” on the Frog forum:]
This is what I’m using. I removed the ugly line breaks that explode creates and added a tagline/description to go after the site name on the home page. Try to view your source from the browser and you’ll see what I mean.
<?php $breadcrumbs = explode(' / ', strip_tags($this->breadcrumbs('/'))); krsort($breadcrumbs); foreach ($breadcrumbs as $key => $val) { if ($key != 0) { echo str_replace("\n", '', $val . ' - '); } else { echo 'your site name'; } } if (!$breadcrumbs[1]) { echo ' | your tagline'; } ?>
