Documentation

Light-weight, fast, simple and powerful!
 
Translations of this page?:

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'; }
?>
1) Surely one of the most complete discussions of this is the article on the topic at Perishable Press; see also its links.
2) Especially useful for tabbed browsers where the identification text on the tab can be very brief.
3) “Sort an array by key in reverse order”; manual.
 
tutorials/breadcrumbs_in_title.txt · Last modified: 2011-09-12 00:46 (external edit)
 
Except where otherwise noted, content on this wiki is licensed under the following license:GNU Free Documentation License 1.2
Copyright 2010 wolfcms.org / design by yello studio / Wolf CMS Inside