2008
Jun
26

Add these to your theme’s template.php

Customizing search results

 
function phptemplate_search_item($item, $type)
{
    $output = ' <dt class="title"><a href="'. check_url($item['link']) .'">'. check_plain($item['title']) .'</a></dt>';
    $info = array();
    if ($item['type']) {
        //Don't output the node type
        //$info[] = $item['type'];
    }
    if ($item['user']) {
    	//Don't output user
       // $info[] = $item['user'];
    }
    if ($item['date']) {
        $info[] = format_date($item['date'], 'small');
    }
    if (is_array($item['extra'])) {
        //Don't output the extra information about the node (comments, attachments)
        //$info = array_merge($info, $item['extra']);
    }
    $output .= ' <dd>'. ($item['snippet'] ? '<p>'. $item['snippet'] . '</p>' : '') . '<p class="search-info">' . implode(' - ', $info) .'</p></dd>';
    return $output;
}

Custom primary links

/*  override item links with injecting span tags in between the link content  */
function phptemplate_primarylinks($links) {
  if (!count($links)) {
    return '';
  }
  $level_tmp = explode('-', key($links));
  $level = $level_tmp[0];
  $output = "<ul class=\"links-$level\">\n";
  foreach ($links as $index => $link) {
    $output .= '<li>';
 
    $titlestr = '<span';
    if (stristr($index, 'active')) {
      $titlestr .= ' class="active"';
    }
    $titlestr .= '>'.$link['title'].'</span>'; 
    $attributes = $link['attributes'];
 
    if (stristr($index, 'active')) {
      $attributes = array( 'class' => 'active');
    }
 
    $output .= "". l("".$titlestr, $link['href'], $attributes, $link['query'], $link['fragment'], FALSE, TRUE) ."</li>\n";
  }
  $output .= '</ul>';
 
  return $output;
}

Update:

Or you can do this quick hack in page.tpl.php:

<?php if(is_array($primary_links)): ?>
<?php foreach ($primary_links as $index => $link): ?>
	<?php
		if (isset($link['attributes']['class']) && stristr($link['attributes']['class'], 'active-trail') == TRUE) 
		{
			$link['attributes']['class'] .= ' active';
		}
		if (isset($link['href'])) print l($link['title'], $link['href'], $link);else print $link['title']; 
	?>
<?php endforeach; ?>
<?php endif; ?>

Custom breadcrumbs

Put the following snippet in your template.php and print your breadcrumbs like this:

<?php if ($breadcrumb): print $breadcrumb; endif; ?>
function phptemplate_breadcrumb($breadcrumb) {
    $home = variable_get('site_name', 'drupal');
    $sep = ' &raquo; ';
    // Check if breadcrumb has more than 1 element.
    // Options: Change to the number of elements/crumbs a breadcrumb needs to be visible.
    if (count($breadcrumb) > 1) {
        $breadcrumb[0] = l(t($home), '');
        /*
            Optional: Include page title in breadcrumb.
 
            drupal_get_title() !== ''
                Check if title blank, if that is the case, we cannot include trailing page name.
            strstr(end($breadcrumb),drupal_get_title()) == FALSE
                Some modules will make it so path or breadcrumb will involve duplication of
                title and node name (such as in the Events module) to remove this, simply
                take out  && strstr(end($breadcrumb),drupal_get_title()) == FALSE
 
            Use: Simply uncomment the if structure below (3 lines).
            Special Use: If you wish to use this regardless of elements/crumbs in a breadcrumb
                simply cut/paste the statements inside the "if (count($breadcrumb) > 1)" outside
                of the structure, and delete the extranneous structure.
 
            if ( (drupal_get_title() !== '') && (strstr(end($breadcrumb),drupal_get_title()) ) == FALSE) {
                $breadcrumb[] = t(drupal_get_title(), '');
            }*/
 
        return '<div class="breadcrumb">'.implode($sep, $breadcrumb).'</div>';
    } else {
        // Would only show a single element/crumb (or none), so return nothing.
        // You can remove this statement.
    }
}
  • Erik
    Changed a little for multisite breadcrumbs and language codes. Thank You :-)

    function phptemplate_breadcrumb($breadcrumb) {
    $site = $_SERVER["HTTP_HOST"];
    $language = explode('/',$_REQUEST['q']);
    if (($site == 'myswissdomain.ch' && $language[0] == 'fr') || ($site == 'www.myswissdomain.ch' && $language[0] == 'fr')){ $home = 'd’accueil'; }
    else {$home = 'Home';}
    $sep = ' » ';

    $breadcrumb[0] = l(t($home), '');

    return ''.implode($sep, $breadcrumb).'';

    }

blog comments powered by Disqus


All rights reserved. © Copyright 2008 MikkoLehtinen.com