I am developing a blog with different categories (taxonomy terms) and I wanted to have custom node templates for the nodes displayed on the blog page and category pages. Because my blog page has a view, I am able to use this template for nodes on that view: node--view--blog.tpl.php. But there is no template I can use for the nodes loaded in www.example.com/category/cat_name (alias for www.example.com/taxonomy/term/3).

I tried suggesting a node template in template_preprocess_node() like this:

if(arg(0) == 'taxonomy') {
  array_push($vars['theme_hook_suggestions'], 'node__view__blog');

The problem with this is that now all the nodes inside that page are rendered with that template, including the ones in my sidebar.

Is there a way to filter inside template_preprocess_node the only ones that are part of the "main content" of the page?


I would recommend you override the default term page with a view, and then theme it like you are doing for your other view. All you have to do is create a view with that same path (taxonomy/term/%) and it will override the default page.

There is even a view already configured for this purpose, you just have to enable it.

On the views listing admin page it is called "Taxonomy term". Just enable and configure this view and then you can override it's themeing.


The preprocess/process function invoked for the node.tpl.php file don't get any information about which region contains the node going to be rendered in the page. If that information is not given from a CSS class present in $variables['classes_array'], the preprocess/process functions don't have any way to get that information.

What you can do is doing as suggested by @rooby, or suggest a template file to use instead of page.tpl.php. See also the information give in hook_page_alter() about how a page rendering array is structured.

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.