By phatmike10 on
I'm trying to customise the breadcrumbs for the Taxonomy pages by adding some code to Template.php. I've done the below which is working but annoyingly results with the following php notice:
Notice: Trying to get property of non-object in allbuyart_breadcrumb() (line 13 of /var/www/vhosts/allbuyart.com/subdomains/drupal7/httpdocs/sites/all/themes/allbuyart/template.php).
Any ideas on how I can change the below code so this notice doesn't appear? It seems to be the variable on line 6 which is causing the above notice: $vid = $term->vid;
function allbuyart_breadcrumb(&$variables) {
$breadcrumb = $variables['breadcrumb'];
$crumbstyling = '<div class="breadcrumbs">';
$tid = (int)arg(2);
$term = taxonomy_term_load($tid);
$vid = $term->vid;
$vocabulary = taxonomy_vocabulary_load($vid);
if(arg(0) != 'taxonomy') {
$lastitem = sizeof($breadcrumb);
$a=1;
foreach($breadcrumb as $value) {
if ($a!=$lastitem){
$crumbstyling .= $value.' > ';
$a++;
}
else {
$crumbstyling .= $value.' > ';
}
}
$crumbstyling .= '<h1>'.drupal_get_title().'</h1></div>';
}
else {
$crumbstyling .='<a href="/">Home</a>'.' > '.'<a href="'.'/'.$term->vocabulary_machine_name.'">'.$vocabulary->name.'</a>'.' > '.'<h1>'.drupal_get_title().'</h1></div>';
}
return $crumbstyling;
}cheers
Comments
.
Usually, that error comes from using an array as an object. Quick check shows that taxonomy_term_load returns an object (according to documentation, anyways). So that leaves two options: or it returns FALSE, or it returns an object that simply doesn't have that property.
Do a var_dump or, if you got the Devel module installed, a krumo to have a look at what exactly's in $term
_
If that truly is the line to which the error refers, dump the $term variable and see what's in it. seems it's not an object.
-
The following code
will also run when looking at a non taxonomy pages (e.g. when visiting node/13293), therefore the taxonomy_term_load function will receive an invalid tid (in the node case the argument would be 13293, which is the nid and not a valid tid).
Maybe this is why you are receiving the error.
Try confirming that you are looking at a taxonomy page first, before using the argument, with something like:
--------------------------------------------
Konordo Ltd
http://www.konordo.com
That's a good call konordo, I
That's a good call konordo, I shall try that out. thanks
worked perfectly thanks
worked perfectly thanks Konordo!