欢迎各位兄弟 发布技术文章
这里的技术是共享的
ZC: With permission from the author, Daniel Hanold, I am pasting in his documentation (below) of how to use Views Arguments to create customized breadcrumbs for Views pages. As of the time of this writing the Custom Breadcrumbs module does not seem to handle Views breadcrumbs is a thoroughly stable fashion, though it appears that it will, so this information may soon be obsolete. Nevertheless, I think the more we can do with Views and other near-core modules, and resort to contrib less, the better. It's a solid piece of documentation. Thanks Danny!source: http://www.danielhanold.com/story/views-breadcrumbs-using-arguments
For most of my clients, I need to create Breadcrumbs. Seemingly easily, breadbrumbs is an area that is a bit more involved than most features in Drupal. There's a great module out there called custom_breadcrumbs. The module works great for the display of breadcrumbs on all node pages, but doesn't (yet) work with views.
After doing some research about a solution for view pages, here's my favorite pick: Views Arguments.
For a simple overview page (that uses views), add a "Global: Null" Argument. Within that argument, select "Provide default argument" and select "PHP Code". In here, you can use the drupal_set_breadcrumb function. That function accepts an array of link titles and paths. Here's an example:
$breadcrumb[] = l('Home', null); $breadcrumb[] .= l('Is The Box Butler For Me?', 'use-cases'); drupal_set_breadcrumb($breadcrumb);
To make this work, it's important to select "Display All Values" for "Action to take if argument does not validate", otherwise the view gets messed up.
To be on the safe side, I've attached a screenshot of the arguments code for this (live) example: http://theboxbutler.com/use-cases.
Recently I needed to add custom breadcrumbs to views 2 generated pages. Now we were using excellent custom_breadcrumbs 1.x to add custom breadcrumbs on site. At that time I discovered that 1.x version of custom_breadcrumbs do not support views generated pages and 2.x version of module (which supports views) is not production stable. So I came up with this solution to create custom breadcrumbs for views pages:
Lets say we have a page view with structure
---Team (menu item)
|
|---Featured 1 (tab-default)
|
|---Featured 2 (tab)
|
|---Featured 3 (tab)
Now instead of having a breadcrumb like "Home ›" OR "Home › Team ›" we need something like "Home › Our Team › Featured 1" for default tab. To accomplish this we need to add following php code in header section of view page with php filter enabled.
<?php
global $base_url;
$breadcrumb[] = l('Home', null);
$breadcrumb[] .= l('Our Team', 'team');
$breadcrumb[] .= l(drupal_get_title(), $base_url.$_SERVER['REQUEST_URI']);
drupal_set_breadcrumb($breadcrumb);
?>
$breadcrumb[] .= l(drupal_get_title(), null);
Thanks for the ideas. It works fine. I want to ask about security... Is it really risky to apply this PHP code ?! At my site it's only user =1 who can use PHP format. Do I need to do something else to guard my site?!
PHP in the UI is bad for so many reasons (security, performance, maintainability, etc.). You'd be better off implementing hook_views_post_view() or hook_views_pre_view(): http://drupal.org/node/99567
Why use .=
instead of =? Dot isn't necessary.
Why not use $_GET['q']
instead of $base_url.$_SERVER['REQUEST_URI']?
来自 http://www.civicactions.com/blog/2010/mar/31/adding_custom_breadcrumbs_views_pages
I want to ask what modification I need to do to this code in order to show "drupal_get_title()" without link to page. I don't need to link to a page that I am currently viewing. Is it possible to only get the page title without linking to it in the breadcrumb trail (line)?!
<code><?php
global $base_url;
$breadcrumb[] = l('Home', null);
$breadcrumb[] .= l('Our Team', 'team');
$breadcrumb[] .= l(drupal_get_title(), $base_url.$_SERVER['REQUEST_URI']);
drupal_set_breadcrumb($breadcrumb);
?></code>