I am using custom breadcrumbs to customize breadcrumbs on my site.

When I use "Breadcrumbs visibility" section with php code, my breadcrumbs disappear.

here is what I did:

  if ( arg(0) == 'products' ) {
    return TRUE;
  }

Am I doing right? much appreciated if anyone can give me a hint.

Comments

cog.rusty’s picture

The arg() function ignores aliases and returns original drupal paths (like node/nnn or taxonomy/term/nnn or admin/user etc). What is 'products'?

Florent Jousseaume’s picture

It may be a view, or a custom path created by module

vj0914’s picture

the products just a URL aliases I give to the URL.

so you think I should use original path?

Florent Jousseaume’s picture

Do you try to display the return value of arg(0) ?
As said cog.rusty, Drupal interprets the alias URL and I am not sure you obtain the result you wish

vj0914’s picture

I found an alternative way to get URL component,

here is what I did:

"\$path = \$_SERVER['REQUEST_URI']; list(\$arg1, \$arg2, \$arg3, \$arg4) = split('/', \$path); \$arg1 == 'products';"

since I am using Custom Breadcrumbs, above code will be inside eval() to determine if "products" is in the url arguments.

for example, if the url is www.site.com/products, then the breadcrumbs will be displayed, otherwise it will not. But right now it's not working yet.

cog.rusty’s picture

Try this then:

$path = trim($_GET['q'], '/');
$path = drupal_get_path_alias($path);
$path = explode('/', $path);

 if ( $path[0] == 'products' ) {
    return TRUE;
}
vj0914’s picture

Thanks a lot cog.rusty, you are my man.

I copied and pasted your code there, and it is working like charm. Thank you so much

Also thanks all people who have helped me on this issue.

jonodunnett’s picture

Hopefully placing this post here isn't bad etiquette. I am having a very similar problem to the original poster...
I am trying to have a different custom breadcrumb display for different languages. For example for the Spanish breadcrumb I put the following in the breadcrumb visibility field:

global $language;
if (($language->name)=='Spanish') {
return TRUE;  
}

The idea is that the breadcrumb (specified but not reproduced here) only shows on the Spanish pages of my site.

Similar PHP code seems to have the desired outcome in normal posts I have tested with so I can't understand why this isn't working. I suspect it is something quite obvious. After several hours trying to see where I am going wrong I could do with a hint, if anyone is reading this...