Does anyone know how to make views display custom breadcrumbs?

I have been thinking you could pass an argument from views? But I have no idea how to do this, or if there is an easier way that I am missing. I am also still unsure if I am putting the correct labels in custom breadcrumbs. I have read and followed these instructions http://drupal.org/node/122654 on how to do this with no success yet.

I have the tokens module installed with custom breadcrumbs 5.x.1-2

Many thanks for the module!

Comments

eaton’s picture

Status: Active » Closed (works as designed)

Views module already creates its own breadcrumb trails using its 'arguments' feature. Custom breadcrumbs was written because it was previously impossible to make *node* breadcrumbs match the breadcrumb trails that views auto-generates for its own pages. custom-breadcrumbs module has no way to alter breadcrumbs on any pages other than node/$nid...

lionstone’s picture

Hi, Eaton, thanks for the help! I think what I need to do is import the view into a node page with a custom breadcrumb. I've been trying this but now the issue is that while the views import fine, the tabs don't reflect the new views...But this isn't an issue for this fourm anymore, I think! Thanks...

mikemccaffrey’s picture

But what if you are not using arguments in your view? What if the view is under /path1/path2/view and you want the breadcrumbs to show Home >> Path 1 Title >> Path 2 Title >> when view the view?

drupalfan2’s picture

HOW can I set the breadcrumb in a "views" when not using arguments!
Please help!

s.Daniel’s picture

following

yopyop’s picture

I was having problems with getting Custom Breadcrumbs to show up on a simple view of node types, (and I'm also using node hierarchy module).

I'm not yet familiar with passing arguments in views, or how that would affect breadcrumbs, but here is a solution that worked for me - I followed the instructions here - http://drupal.org/node/158583 in experimenting with the weights of the custom breadcrumb module in the system table - I set it to 1 instead of 0, and it worked, breadcrumbs set for that node type show up now.

psynaptic’s picture

Don't know if anyone is still following this issue but if you need to have a breadcrumb for a View you can define it in template.php:

/**
 * Override, use a better default breadcrumb separator.
 *
 * Return a themed breadcrumb trail.
 *
 * @param $breadcrumb
 *   An array containing the breadcrumb links.
 * @return a string containing the breadcrumb output.
 */
function phptemplate_breadcrumb($breadcrumb) {
  if ($_GET['q'] == 'case-studies/client-testimonials') {
    $breadcrumb[] = l('Case Studies', 'case-studies');
  }
  if (count($breadcrumb) > 1) {
    // $breadcrumb[] = drupal_get_title();
    if ($breadcrumb) {
      return '<div class="breadcrumb">'. implode(' &rsaquo; ', $breadcrumb) ."</div>\n";
    }
  }
}
abu3abdalla’s picture

thank you but would u please make it for DRUPAL 6 to help the community

MGN’s picture

I have posted a patch extending custom breadcrumbs for views (with or without arguments) for 6.x-1.4 at #323816: Extending custom_breadcrumbs for views, paths, and panels. It needs testing, but is working for me and might be of help.

nocte’s picture

@psynaptic: this code doesn not have any effect in my Druapl 6.. :-(

capellic’s picture

IT works fine in Drupal 6. Be sure you adjust the "if" statement to match the path for the breadcrumb you want to manipulate.

In my case, I have a View that lists all of my "News" content types. The path of the View is "news/category" and it accepts the term id as an argument (and this is why I am using the substr function to only get the first 13 characters). I want any argument filtering of the View to show show a "News" breadcrumb. This is how I did it:

function theme_breadcrumb($breadcrumb) {
	
  if (substr($_GET['q'], 0, 13) == 'news/category') {
    $breadcrumb[] = l('News', 'news/');
  }
  
  if (count($breadcrumb) > 1) {
    if ($breadcrumb) {
      return '<div class="breadcrumb">'. implode(' &rsaquo; ', $breadcrumb) ."</div>\n";
    }
  }
}

If course, you will have to adjust your path and length of the substr to match the length of the path.

londondave’s picture

I am using drupal 6

I have the custom breadcrumbs module installed and I am stuck with how to get this to work with views. Maybe it's not possible, but as an example, what I need is the following:

user clicks on a front page link of say 'film reviews:scifi' which is a view with path: views/films/filmsview_scifi. I need a way to build this path using tokens?

Title would be [term]
path would be views/films/?

how do i get the view title dynamically using tokens? I have multiple film review views eg 'film reveiws: action' etc, so the last bit of the view path 'filmsview_scifi', filmsview_action' etc needs to be built dynamically?

At this point the breadcrumb would be home >> films:sci-fi, if the user clicks on films:sci-fi it needs to go back to the view

Then in the view page there are rows of film title links, user might click on row 1 with title 'sphere' which is a link to path: content/films/scifi/443-sphere. How would you create a custom breadcrumb for this part?

The breadcrumb should look like:

home >> films:sci-fi >> 443-sphere

Any ideas would be greatly appreciated. Something tells me there must be a way to do this with the custom breadcrumbs module for drupal 6.

At this point my titles look like:

[term]
[nid]-[title]

And paths look like:
views/films/?
content/films?

How do you build these paths and can it work?

My email is desktopdave@tiscali.co.uk

londondave’s picture

Version: 5.x-1.2 » 6.x-1.4
MGN’s picture

Two possibilities:

Views support is now in custom breadcrumbs 6.x-2.x-dev for testing. The tokens that you want are arg(x). See #273893: Argument tokens using arg() for a patch. It looks like this is destined for the token starter kit, but that patch still needs to be tested and committed. So your feedback on that issue would also be helpful.

You can also See #424464: CB for Views: let views create customizable breadcrumbs for a views patch that allows setting the breadcrumb as you edit the view.

I hope this helps. Since views support is still being developed for custom_breadcrumbs, please report back when you identify the solution that works for you.

Thanks

londondave’s picture

Thanks for that.

Setting the breadcrumb in the view itself is a good idea, but I am a bit wary of using patches. The patch they have there is for 2.4 while views for drupal 6 is now 2.5.

At the moment using the custom breadcrumb module as you say above there is no way to get that last argument for say views/films/actual-views-path-name

I have so far

Title

[term] -this works
[title]-this works

Path

views/films/??? tried [tid] but not accepted as a token, tried [nid] still no good.
node/[nid] -this works

So if you could tell the custom breadcrumb module to use the path to the current page for the view eg

views/films/[path-completed]

then it would work, the last line would need a token that would complete the path in the address bar?

MGN’s picture

Yes. The arg tokens return any part of the path, either aliased or raw. So you'll need to either test out the token starter kit (with token 6.x.1.x-dev) and greggles patch at #273893: Argument tokens using arg(), or wait until others do and it gets released in the next stable version. I am using arg tokens for my views pages they work fine for my needs. Sorry, at this point its all dev code, so be cautious (or adventurous?). But the more people that test, the faster it becomes stable... ;-)

londondave’s picture

Thanks for the advice MGN, I think I will give it a try and let you know how it goes.

So I patch token module 6.x.1.x-dev with the last greggle patch on the page '#273893: Argument arg() support in Token' (comment #16)? That downloaded as 'views_argument_breadcrumbs.patch'

I'm a bit confused with which token dev module and which patch?

Thanks for your help.

mroscar’s picture

deleted... my solution was ... funny

dooug’s picture

RE:#7 Wonderful! The phptemplate_breadcrumb was just what I was looking for. Although I did find that the following code was unnecessary:

 if (count($breadcrumb) > 1) {
    // $breadcrumb[] = drupal_get_title();
    if ($breadcrumb) {
      return '<div class="breadcrumb">'. implode(' &rsaquo; ', $breadcrumb) ."</div>\n";
    }
  }

I'm looking forward for the Custom_Breadcrumbs 6.x-2.x working with views.

londondave’s picture

Version: 6.x-1.4 » 6.x-2.0-beta2

Hi,

I have a custom front page of links to views, my breadcrumbs need to work like this:

home >> path to view from frontpage link >> nid-title of node eg:

home >> cars >> 189-cars-that-use-cooking-oil

I can set the path to the view on the custom breadcrumbs 2 admin page, so in the above case 'cars' is the title given to the view path- clicking 'cars' works, it takes the user back to the view page.

The view page produces a table of links to nodes that is taxonomy based, so how do I set the breadcrumb to just get 'nid-titleOfNode', without it recreating the breadcrumb path and removing the working 'cars' view breadcrumb?

MGN’s picture

@londondave, can you open a new support request. I nearly missed your request because it was tacked on to an old issue with status 'by design.' We can address your question more fully on a new issue.

When you open it, please indicate on what type of page are you trying to get the breadcrumb to be
home >> cars >> 189-cars-that-use-cooking-oil

Is this a breadcrumb for a node or a view page (or something else)? What type of breadcrumb have you tried to create for these pages? Also, indicate what you have tried to put in the titles and paths sections.

For the path nid-title of node (assuming you are using pathauto) have you tried

<pathauto>|[nid]-[title]
solona’s picture

Thanks for #7!

It helped me write a function that sets the breadcrumb based on the path alias, which seems intuitive to me. It supercedes the need for the Custom Breadcrumb module.

*(In cases where your alias does not match the page title, you will need to write these manually. Eg: An About Us page with the alias of 'about')*

function theme_breadcrumb($breadcrumb) {
	$normal_path = trim($_GET['q'], '/');
	$path_alias = drupal_get_path_alias($normal_path);
	$alias_parts = explode('/', $path_alias);
	
	// Set the page title by capitalizing the first letter of the alias
	$page_title = ucfirst($alias_parts[0]);
	
	if ($alias_parts[0] != $path_alias) {
		$breadcrumb[] = l($page_title, $alias_parts[0]);
		$breadcrumb[] = l(drupal_get_title(), $normal_path); // Link to current URL
	}
	// In order to avoid duplicating the top level path, check for a top level page
	else if ($alias_parts[0] == $path_alias) {
		$breadcrumb[] = l(drupal_get_title(), $path_alias);
	}
	
  if (count($breadcrumb) > 1) {
    // $breadcrumb[] = drupal_get_title();
    if ($breadcrumb) {
      return '<div class="breadcrumb">'. implode(' &rsaquo; ', $breadcrumb) ."</div>\n";
    }
  }
}
rplescia’s picture

Stupid question but do i put this piece of code in the template.php file?

solona’s picture

Yes.

rplescia’s picture

thanks

solona’s picture

laevensv@gmail.com’s picture

Thanks a lot, solona !

For my need i just added a piece of code to avoid breadcrumb looks like "content>title"

if ($alias_parts[0] != $path_alias) {
if($page_title == "Content") {
$breadcrumb[] = l(drupal_get_title(), $path_alias);
}else {
$breadcrumb[] = l($page_title, $alias_parts[0]);
$breadcrumb[] = l(drupal_get_title(), $normal_path); // Link to current URL
}
}

gbrands’s picture

I was getting an array to string error so I modified the code in post #22 to this:

function dartik_breadcrumb($variables) {
    $breadcrumb = $variables['breadcrumb'];
    $normal_path = trim($_GET['q'], '/');
    $path_alias = drupal_get_path_alias($normal_path);
    $alias_parts = explode('/', $path_alias);
    
    // Set the page title by capitalizing the first letter of the alias
    $page_title = ucfirst($alias_parts[0]);
    
    if ($alias_parts[0] != $path_alias) {
        $breadcrumb[] = l($page_title, $alias_parts[0]);
        $breadcrumb[] = l(drupal_get_title(), $normal_path); // Link to current URL
    }
    // In order to avoid duplicating the top level path, check for a top level page
    else if ($alias_parts[0] == $path_alias) {
        $breadcrumb[] = l(drupal_get_title(), $path_alias);
    }
    
  if (count($breadcrumb) > 1) {
    // $breadcrumb[] = drupal_get_title();
    if ($breadcrumb) {
      return '<div class="breadcrumb">'. implode(' &rsaquo; ', $breadcrumb) ."</div>\n";
    }
  }
}
opegasus’s picture

Component: Miscellaneous » Code
Category: support » task
Status: Closed (works as designed) » Active

#'s 22 & 28 Almost worked for me...thanks. Did print the links but unfortunately clicking back on those links either worked or came back to "page not found" error. Soooo close. Plus in one instance it switched the order of the links...odd.

The pages are being created by Views so I wonder if I must either use Custom Breadcrumbs or figure out how to use the Views Breadcrumb feature?

Nice work on those two PHP snippets though. Hopefully they will work for others.
P.S. I actually had to put the code into includes/theme.inc because when it was placed in template.php, 'includes' threw a fit and erred out the site.

adelka’s picture

Works for me!

Just wto question - is ist possible to:
- change "home" text to something else
- make current node title not clickable (no )

Thank you!

rakesh.gectcr’s picture

Title: Making custom breadcrumbs for views pages » Views breadcrumb module

Please check this module

Views bread crumb modue

https://drupal.org/sandbox/rakeshjames/2049937

lamp5’s picture

Issue summary: View changes
Status: Active » Closed (outdated)