Hello Readers ,
Breadcrumbs or breadcrumb trails are a graphical control element used as a navigational aid in user interfaces. It allows users to keep track of their locations within programs, documents or websites.
So in this blog I will help you to use Breadcrumb module in my tpl.php file in drupa
Use custom breadcrumb code : -
function Your_theme_breadcrumb($variables) {
$arg = arg();
$breadcrumb = $variables["breadcrumb"];
/** change breadcrumb for hotels gallery **/
if(isset($arg[0]) && $arg[0] == 'hotel-gallery'){
if(isset($arg[1]) && is_numeric($arg[1])){
$node = node_load($arg[1]);
$path = drupal_get_path_alias('node/' . $node -> nid);
$node = $node->location['city'];
$breadcrumb[1] = '<a href="/' . $path . '">Budget Hotels in ' . $node . '</a>';
}
}
/** change breadcrumb for hotels gallery end **/
/** change breadcrumb for hotels **/
if (isset($arg[0]) && $arg[0] == 'node' && isset($arg[1])) {
$node = node_load($arg[1]);
if ($node -> type == 'hotels') {
unset($breadcrumb[1]);
$city_url = $node -> field_city[LANGUAGE_NONE][0]['tid'];
$city_url = '/our-hotels?field_city_tid=' . $city_url;
$path = drupal_get_path_alias('node/' . $node -> nid);
$path = explode("/", $path);
if (count($path) > 1) :
foreach ($path as $index => $values) :
$values = str_replace("-"," ",$values);
$values = ucwords($values);
if ($index == 0) {
$breadcrumb[$index + 1] = '<a href="' . $city_url . '">' . $values . '</a>';
} else {
$values = str_replace("Hotels","Hotel",$values);
$breadcrumb[$index + 1] = array('data' => $values);
}
endforeach;
endif;
}
}
/** change breadcrumb for hotels end **/
$items = '<ol class="breadcrumb" itemscope itemtype="http://schema.org/BreadcrumbList">';
foreach ($breadcrumb as $key => $values) :
$items .= ' <li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem">';
if (is_array($values)) {
$items .= '<span itemprop="name">' . $values['data'] . '</span>';
} else {
$dom = new DOMDocument;
$dom -> loadHTML($values);
$data = array();
foreach ($dom->getElementsByTagName('a') as $node) {
$data["href"] = $node -> getAttribute('href');
$data["text"] = $node -> nodeValue;
}
$items .= '<a itemprop="item" href="' . $data["href"] . '"><span itemprop="name">' . $data["text"] . '</span></a>';
}
$items .= '<meta itemprop="position" content="' . ($key + 1) . '" /></li>';
endforeach;
$items .= '</ol>';
return $items;
}
0 Comment(s)