Download & Extend

Malformed breadcrumb on taxonomy/term override pages

Project:Views
Version:5.x-1.x-dev
Component:Documentation
Category:task
Priority:normal
Assigned:Unassigned
Status:closed (fixed)

Issue Summary

If I use views to override the "Taxonomy/Term" page the breadcrumbs on "Taxonomy/Term" pages do not work anymore (I only get "Home", nothing more). I would expect - as long as I haven't changed anything on the view - that I would get the same breadcrumbs as with the default "Taxonomy/Term" pages (which indicate the terms in the hierarchy)

Comments

#1

Yip, I've having the same problem.

The taxonomy_breadcrumb module stopped working when I started using the taxonomy/term override. It seems to work only when you load the node. However, at each term level (i'm using term hierarchy) and at the main vocabulary level, the breadcrumbs are not working.

I tried looking at the code for the view module, but it's a little too technical for me at this point being a new drupal user.

I'll leave it to the experts for their advice/fix.

thanks

#2

Category:bug report» feature request

Ok, this turns out to be a tough one; it's not technically a bug because it's a feature that Views simply doesn't have, and I'd never thought about. Switching it to a feature request. I put a little time into trying to add this, but it has a lot of ramifications that'll take quite awhile to work out.

#3

Somewhat related to http://drupal.org/node/126313.

#4

Hi I ran into this issue also. I'm not sure if this is helpful but I was able to devise a workaround with the Viewfield module and CCK. Creating a separate node that contains the view enables the taxonomy_breadcrumbs to work as expected. It's a little extra work but does the trick...

Cheers,
Eric

#5

Sounds to me that the views theme (in template.php) is rendered way before the taxonomy_breadcrumb is called in... so at the time the engine renders the view, the static breadcrumb is not already updated.

In taxonomy_breadcrumb, it occurs during the nodeapi hook.

#6

Quick and (very) dirty fix in your template.php overriding function:

<?php
function YOURTHEME_views_view($view, $type, $nodes, $level = NULL, $args = NULL) {
   
$num_nodes = count($nodes);

    if (
$type == 'page') {
       
drupal_set_title(filter_xss_admin(views_get_title($view, 'page')));
/*
if we are in the taxonomy view, pre-override the breadcrumb because taxonomy_breadcrumb is too late... well.. this is quick, might want to add some more checks (aliasing, well formed urls...), and verify that the taxonomy_breadcrumb actually exists.
the result is actually that this taxonomy_breadcrumb_generate_breadcrumb function will be called twice (once here, the second time during the nodeapi call)
*/
       
if ( $view->url == 'taxonomy/term')
           
drupal_set_breadcrumb(taxonomy_breadcrumb_generate_breadcrumb($args[0]));
        else
           
views_set_breadcrumb($view);
...
?>

#7

Category:feature request» bug report

I may be seeing a variation of this issue. I have a 5.1 site with the latest Views and Tax-Breadcrumbs.
It is using the Golden Hour theme.

To see the problem, do this:
Go to http://www.sargasso-sea.net
In the Nav column, click on "Poetry"
This produces a Views-generated list View of some Pages. Click any poem in the list
When it opens there is a tag out to the right - click on that OR click on the word "Poetry" at the top
This will take you to a broken page - the whole left region is gone and the CSS appears to be messed up.
You can go back and forth and see the nav-bar and background change.

I put the patch in (on a local server) and it totally kills the View from showing anything.

=Alan R.

#8

The patch above does the same thing to my view, it disappears.

#9

Patch above is now working for me with beta5. Thanks laurentchardin, this solves a major headache.

#10

Should there be a check first to see if taxonomy_breadcrumb is installed and enabled? What happens if you disable the taxonomy_breadcrumb module and look at your views page? Do things blow up?

#11

Good call, I've added to the code a check for taxonomy_breadcrumb

function phptemplate_views_view($view, $type, $nodes, $level = NULL, $args = NULL) {
  $num_nodes = count($nodes);

  if ($type == 'page') {
        drupal_set_title(filter_xss_admin(views_get_title($view, 'page')));
/*
if we are in the taxonomy view, pre-override the breadcrumb because taxonomy_breadcrumb is too late... well.. this is quick, might want to add some more checks (aliasing, well formed urls...), and verify that the taxonomy_breadcrumb actually exists.
the result is actually that this taxonomy_breadcrumb_generate_breadcrumb function will be called twice (once here, the second time during the nodeapi call)
*/
        if ((module_exists('taxonomy_breadcrumb')) && $view->url == 'taxonomy/term')
            drupal_set_breadcrumb(taxonomy_breadcrumb_generate_breadcrumb($args[0]));
        else
            views_set_breadcrumb($view);
  }

Disabling taxonomy_breadcrumb just results in the crappy breadcrumb coming back -- without the check, you're right, it explodes.

#12

This worked for a while, nice breadcrumbs, nice view. Now it is broken. Nice breadcrumb, view is *empty*. What happened?

#13

Disappearing view problem solved; this snippet can be moved into the "argument handling code" section of the view, instead of putting it into the theme template.

#14

What piece of snippet please?
Could you state exactly what needs to be put in argument handling?

Thanks in advance,
greetings,
Martijn

#15

Instead of using phptemplate_views_view to override the breadcrumb (as in the example above), I now just put the code into the argument handler section of the taxonomy_term view. I can't say exactly why putting it into hook_views_view didn't work... it just... didn't. :(

Actually this seems a bit more elegant to me, and does not require any "checks" to make sure that the taxonomy_term view is actually active, since it is attached directly to that view, and there is also zero possibility of the hook interacting with some *other* view. I've also re-used the same trick to customize the breadcrumbs on a number of other views where the default behavior of the argument handler doesn't create the breadcrumb trail that I want.

#16

Component:User interface» Documentation
Category:bug report» task

Would someone be willing to write this up in the Views Snippets section, (reference this issue) and then mark this issue fixed?

#17

Is there a fix to this yet?

#18

Another dirty/easy solution based on "bsuttis" solution:

Edit the views.module file -> in function "views_set_breadcrumb" ->

Replace

drupal_set_breadcrumb($breadcrumb);

for

<?php

if ((module_exists('taxonomy_breadcrumb')) && $view->url == 'taxonomy/term')
   
drupal_set_breadcrumb(taxonomy_breadcrumb_generate_breadcrumb($args[0]));
else
   
drupal_set_breadcrumb($breadcrumb);
?>

At least it works for me!.


Taxonomy context 5.x-1.x-dev
Taxonomy breadcrumb 5.x-1.4
Views 5.x-1.6

#19

Andyschm, would you mind sharing exactly what code you include in the argument handler section of the view? (http://drupal.org/node/114548#comment-502154)

#20

Adminster > Views > Edit "taxonomy_term" (override) > Argument Handling Code:

if ($type == 'page') {

        drupal_set_title(filter_xss_admin(views_get_title($view, 'page')));

        if ($view->url == 'taxonomy/term') {

          $tid = array_shift(explode(',', $args[0]));  // in case of refine_by_taxo module, takes the first tid
          $term = taxonomy_get_term($tid);
          $vocabulary = taxonomy_get_vocabulary($term->vid);
          $parents = taxonomy_get_parents($term->tid);

          $breadcrumbs = array(l(t('Home'), ''));

          foreach($parents as $parent_term) {
            $breadcrumbs[] = l(t($parent_term->name), $parent_url . '/' . drupal_strtolower(pathauto_cleanstring($parent_term->name)));
            $parent_url = $parent_url . '/' . drupal_strtolower(pathauto_cleanstring($parent_term->name));
          }

          drupal_set_breadcrumb($breadcrumbs);
        } else {
          views_set_breadcrumb($view);
        }

}

This snippet also generates the URLs to the parent term pages according to how pathauto would... YMMV; replace that bit with just the tid if you are not using pathauto to alias the term pages.

#21

Version:5.x-1.5» 5.x-1.6-beta5

emlomar1's 3 liner solution has worked for me very nicely as well! Latest Drupal 5, breadcrumb and views modules :)

I hope it will be committed to the core views module

#22

nothin' for me yet, after inserting the argument code from #20

#23

This is the exact code (minus php brackets) I use in the argument handler field (adapted from comment #11 above). It's been working well for me.

<?php
 
if ($type == 'page') {
       
drupal_set_title(filter_xss_admin(views_get_title($view, 'page')));
/*
if we are in the taxonomy view, pre-override the breadcrumb because taxonomy_breadcrumb is too late... well.. this is quick, might want to add some more checks (aliasing, well formed urls...), and verify that the taxonomy_breadcrumb actually exists.
the result is actually that this taxonomy_breadcrumb_generate_breadcrumb function will be called twice (once here, the second time during the nodeapi call)
*/
       
if ((module_exists('taxonomy_breadcrumb')) && $view->url == 'taxonomy/term')
           
drupal_set_breadcrumb(taxonomy_breadcrumb_generate_breadcrumb($args[0]));
        else
           
views_set_breadcrumb($view);
  }
?>

I tried andy's code also (#20) but there was some version incompatibility.

#24

no luck. now im thinking its something to do with my configuration. should be outputting 'vocabulary name > term' but its not, for any of my taxonomy based views. appreciate the help anthonym but i think my problem may be somewhere else and i'm being slow in grasping it.

#25

subscribing.

#26

I'm using this in the argument handling code and it seems to be working. Cribbed from taxonomy.module

<?php
          $current
= taxonomy_get_term($args[0]);
         
$breadcrumbs = array(array('path' => $_GET['q'], 'title' => $current->name));
          while (
$parents = taxonomy_get_parents($current->tid)) {
           
$current = array_shift($parents);
           
$breadcrumbs[] = array('path' => 'taxonomy/term/'. $current->tid, 'title' => $current->name);
          }
         
$breadcrumbs = array_reverse($breadcrumbs);
         
menu_set_location($breadcrumbs);
?>

#27

George, that looks very useful. Thanks!

#28

If that works for people, a post in the views snippets section would be lovely (and marking this fixed).

#29

Title:Taxonomy/Term override causes breadcrumbs issue» Malformed breadcrumb on taxonomy/term override pages
Version:5.x-1.6-beta5» 5.x-1.x-dev

#30

Status:active» fixed

The code in #26 seems to work well, so I created a book page for it: http://drupal.org/node/449192. Setting to fixed.

#31

Reliving this problem on Drupal 6 - any suggestions on how to fix it there?

#32

Status:fixed» closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

#33

The following code solved the problem for me under Drupal 6 (taxonomy_breadcrumb 1.0, views 2.6). Put this into your template.php:

<?php
/**
* Implements theme_breadcrumb().
*/
function phptemplate_breadcrumb($breadcrumb) {
  if ((
module_exists('taxonomy_breadcrumb')) && arg(0) == 'taxonomy' && arg(1) == 'term' && is_numeric(arg(2))) {
    require_once(
drupal_get_path('module', 'taxonomy_breadcrumb') . '/taxonomy_breadcrumb.inc');
   
$breadcrumb = _taxonomy_breadcrumb_generate_breadcrumb(arg(2));
  }

  return
theme_breadcrumb($breadcrumb);
}
?>

Cheers

#34

@drimsun
thanks, works great.

#35

Version:5.x-1.x-dev» 6.x-2.8
Status:closed (fixed)» active

the drimsum solution didnt work, the solution in #26 is for Drupal 5 and the solution in http://drupal.org/node/599442 doesnt seem to work...

#36

eiland try clearing your cache or swopping to another theme and then changing back to the original theme. #33 worked for me, thanks drimsun!

#37

#33 did not work for me (drupal 6.16, views 6.x-3.0-alpha3, taxonomy_breadcrumb 6.x-1.1)

What calls this function?

Do I need to rename the function when it is called?

Do I need to rename the return statement at the end and substitute "theme" by the name of my theme?

Thanks for your help!

Christian

#38

Version:6.x-2.8» 5.x-1.x-dev
Status:active» closed (fixed)

Please do not take closed issues for Views for Drupal 5 and make them Views for Drupal 6 issues. THey're not similar

#39

Thanks, this work too well,
/clap

nobody click here