Quantcast
Channel: Recent posts across whole site
Viewing all articles
Browse latest Browse all 49197

Create a view to display content of a taxonomy term, which also displays the taxonomy term as the page title in the correct language

$
0
0

By default, taxonomy pages display content in chronological order, and this is not customizable unless you update the core module.

To get around this, create a view with taxonomy term as the argument, simple (if you're new to views and arguments, check-out this tutorial video: http://gotdrupal.com/videos/drupal-views-arguments).

In the argument settings, if you enter %1 as the title override, the page title will become the Taxonomy term of the taxonomy id argument, BUT this method fails to show the translated string if you're not viewing the page in the default language.

To get around this, instead of using the argument title override, use php in your view's header setting:

<?php
// get language properties of current language
global $language;
$lang = $language->language;

// get the argument from view and get the term properties
$view = views_get_current_view();
$tid = $view->args[0];
$term = taxonomy_get_term($tid);

// if term exists, get term name in current language
if($term){
$name = $term->name;
$mytitle = tt("taxonomy:term:{$tid}:name", $name, $lang,FALSE);
}
else {
// provide a default title if no argument was given, replace "default_title" with desired title
$mytitle = t(default_title);
}
print
"<h1 class='title'>".$mytitle."</h1>";
?>

Viewing all articles
Browse latest Browse all 49197

Trending Articles