5

How do I configure a view to allow me override only term pages within a specific vocabulary without overriding all other term pages?

Edit: Due to the requirements of the project, this must be done with a view and not overridden with a custom tpl.

2
  • Did you find a solution? If yes can you please post it?
    – znat
    Jan 24, 2013 at 17:41
  • I added an answer below with what I ended up doing Jan 24, 2013 at 18:17

4 Answers 4

8

I ended up using the Taxonomy Views Integrator module.

The TVI (Taxonomy Views Integrator) module allows selective overriding of taxonomy terms and/or vocabulary with the view of your choice. Using TVI you can easily create custom views to output all terms in X vocabulary.

1
  • 1
    This should be in the core taxonomy module or get integrated into views - works like a charm! Sep 23, 2014 at 21:54
3

If i were you I'd try the using the Pages module functionality combined with views for your display and contexual filters to show the taxonomy according to vocabulary. Simply enable the taxonomy template page(admin/structure/pages). The contexts comes set so all you have to do is create a View with a contexual filter to that the taxonomy page as a block field and place it on that page. you should be able to figure out the rest ;}

2
  • What is the pages module? drupal.org/project/pages or if you are referring to something in the panels sphere, using panels is not an option on this project. Oct 17, 2012 at 2:22
  • I think he means page_manager which is related to Panels and an excellent suggestion to solving this kind of problem.
    – danbohea
    Nov 5, 2013 at 17:19
2

If what you are asking is how do you override

www.yoursite.com/taxonomy/term/138

when term 138 is of a certain vocabulary, but leave

www.yoursite.com/taxonomy/term/139

alone when it's not, you should be able to copy taxonomy-term.tpl.php from the taxonomy module's directory to your theme and modify it.

In it, it basically does this:

<div id="taxonomy-term-<?php print $term->tid; ?>" class="<?php print $classes; ?>">

  <?php if (!$page): ?>
    <h2><a href="<?php print $term_url; ?>"><?php print $term_name; ?></a></h2>
  <?php endif; ?>

  <div class="content">
    <?php print render($content); ?>
  </div>

</div>

and you could change it to something along the lines of

<div id="taxonomy-term-<?php print $term->tid; ?>" class="<?php print $classes; ?>">

  <?php if (!$page): ?>
    <h2><a href="<?php print $term_url; ?>"><?php print $term_name; ?></a></h2>
  <?php endif; ?>

  <div class="content">
    <?php if ($term->vid==VOCABULARY_IN_QUESTION): ?>
      <?php print views_embed_view(VIEWYOUWANT, 'default', $term->tid); // or any other content you want printed out instead of the default
    <?php else: ?>
      <?php print render($content); ?>
    <?php endif; ?>
  </div>

</div>

I say should because I only know D7 intellectually (if that lol) and don't have a test bed, but I've done similar with D6. There is a great tutorial Crazy Awesome Taxonomy Pages also based on D6 that might be of help in giving you some ideas you could "port" over to your D7 installation.

ADDITION: To your question of using the supplied default views: if you want to use them, you may have to enable them, grab the one your want for this specific case, eg, taxonomy/term/%, and clone/copy it and then disable the supplied one and then in the new cloned one, remove the page menu stuff so Views doesn't use it there anymore and is instead called directly from here. I can't think of a better way of explaining this but maybe someone out there can help :) Of course, if you write your own view, this isn't needed.

2
  • Unfortunately, using the tpl file to override the page is not an option either. It must use a view as I am using the output to connect to a mediafront player. And as such needs to be based on a view. Oct 17, 2012 at 16:41
  • This is bad solution. Using views_embed_view in template is calling another view inside already rendered one, so its like rendering 2 views. Which means you will have much more queries, more memory taken and slower page generation speed. Instead use out of the box TVI module and solve it with that. drupal.org/project/tvi
    – Blissful
    Sep 15, 2016 at 8:06
1

Perhaps the project taxonomy display would work for you. It integrates with panels and display suite, but does not require them. It may require some hooks to get the right effect; these would look a lot like @Jimajamma's custom taxonomy term template answer (which would also work fine).

It's too bad that panels is not an option. With panels, you could define your selection rules to filter on the taxonomy term's vocabulary, and just drop your existing view into the panel content. You could create a variant for the other vocabularies that output the standard taxonomy term display. This would be very fast to put together, wouldn't require any custom coding, and wouldn't have to affect any pages on the site except taxonomy terms. One of the other alternate solutions will probably work just as well, though, with perhaps just a bit more effort.

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.