0

I created a taxonomy, called Galleries for images on the web site:

  1. Our Rooms
  2. Our Food and wines
  3. Our Services

Then I created a gallery for each of the terms, using views. I wanted to override the title of gallery to the term value, as it is shown in this subform for Contextual filters:

enter image description here

But the id of term is used in the url:

http://hotelcentralpark.ro/gallery/1

http://hotelcentralpark.ro/gallery/2

etc

So, instead of words: "Our Rooms", "Our Food and wines" I get "1" and "2", if I check the box "Override title".

How can I show the value of the term instead of it's id? But keep id in the url.

1

Try to use the hook_views_pre_render on your view to override the page title

function custom_views_pre_render($view) {
  if ($view->name == 'your_view_name') {
    // get the $tid from the view's args
    $term = taxonomy_get_term( $view->args[0] );
    if( $term ){
      drupal_set_title( $term->name );
    }
  }
}
0

Create the function, using hook_views_pre_render

function custom_views_pre_render($view) {
      if ($view->name == 'gallery') {
            // get the $tid from the view's args
            $term = taxonomy_term_load( $view->args[0] );
            if( $term ){
                  $view->build_info['title'] = $term->name;
            }
      }
}

Mind, that in Drupal 7 drupal_set_title doesn't work for views:

https://stackoverflow.com/questions/8343623/drupal-7-drupal-set-title-not-working-in-views

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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