0

I am using the following PHP code in the view's header to set the breadcrumbs of the view.

global $base_url;
$path = $base_url . "/tag/" . arg(1) . "/" . arg(2);
$title = ucfirst(str_replace("-", " ", arg(2)));
drupal_set_title($title);
$breadcrumb = array();
$breadcrumb[] = l('Home', '<front>');
$breadcrumb[] = l($title, $path);
drupal_set_breadcrumb($breadcrumb);
print views_embed_view('article_tag_name', 'default', array(arg(2)));

In my page, the breadcrumbs contain the term ID, not the term name. How do I get the term name?

0

1 Answer 1

0

Seems like your breadcrumb is working properly but you get the real path instead of the path alias. You can use drupal_get_path_alias.

$breadcrumb[] = l($title, drupal_get_path_alias('taxonomy/term/'. arg(2)));

Seems like you are setting title and breadcrumb in a .tpl file? Try to avoid that and put your logic in template.php.
Quick tip: views_embed_view can cause performance issues.

5
  • i want term name insted of term id.but it shown term id.in my view in argument i put Taxonomy: Term ID.and in basic setting>header a php code.but it's showing term id not term name can you tell me relly good for this.........
    – trilok
    May 18, 2013 at 7:21
  • how to put this into this <?php global $base_url; $path = $base_url."/tag/".arg(1)."/".arg(2); $title = ucfirst(str_replace("-"," ",arg(2))); drupal_set_title($title); $breadcrumb = array(); $breadcrumb[] = l('Home', '<front>'); $breadcrumb[] = l($title, $path); drupal_set_breadcrumb($breadcrumb); print views_embed_view('article_tag_name', 'default', array(arg(2))); ?>
    – trilok
    May 18, 2013 at 7:49
  • Using the path alias still isn't ideal because it will generally be lower case with punctuation and small words removed. Use taxonomy_term_load() to get the term and then $term->name to get the proper name. Also, this is more functionality than design/visual so it would be better in a custom module than in the theme. But either is better than in the views UI.
    – rooby
    May 19, 2013 at 2:48
  • I agree it is a horror debugging php code in fields!
    – JurgenR
    May 19, 2013 at 6:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.