Crazy-Awesome Taxonomy Pages

In this episode, Bob will blow away your current perspective on Drupal's core taxonomy pages. By default, they're boring lists of content, but with a little magic and a few template overrides, these can be the coolest pages on your site. Please Note: A few follow up comments below point out that what I show here can be done using the taxonomy term description without creating a content type. That's true, but you're missing my point. By using CCK based nodes, you can add MANY other types of information than just a description. Take what I show here as an example for many things you can do, not as the showing of something specific. (see my "sure just an example" comment below)

I really enjoy your videocasts, perfect for a fellow themer. Looking forward to the grid episode.
This was perfect. I am building the most boring Taxonomy page! It's a river of content that flows into the footer. You just gave me some great ideas!
Hey Bob, more great stuff, as usual. I had the hardest time understanding Arguments until some kind soul in IRC explained, "It's like a filter that's passed through the URL." AHH! Blesssings! -NP
That was EXACTLY what I needed. I was fighting with this over the weekend. Thanks SOO much! Really looking forward to the Panels one.
Can you pull the description field that is already in each taxonomy term? It seems to be a bunch or work to create a node for every term on your site. Also if you used a module like taxonomy image to associate an image/icon with the taxonomy term could you pull that information when building this new term page? Thanks for a great video podcast, hope to catch up with you July 14th in Detroit.
Hey Tim, For sure...if you wanted to do what I showed here, it would be easier to just use the term description, build a view, and display that using almost this same method. But often times, a 'description' might contain MANY CCK fields (images, dates, contact forms, or anything else)...by using a node, I was intending to just show how flexible this method could be... This isn't limited to 'descriptions' either. I've used it to show things like 'related content' to the taxonomy term or other stuff that's not tagged with that taxonomy but is in some other way related to the node. The idea here was to just show the method, then let you come up with cool uses for your situation.
First, views provides a taxonomy/term override which you could make into what you want. Well, it doesn't let you do as you did in the podcast of separating out different node types into different lists. Hmm.. hafta think about this. But more important why create a second content type for a taxonomy description? Taxonomy module already provides a description per term, so why not just display the existing description? http://api.drupal.org/api/function/taxonomy_get_term/6
Just saw someone else asked the same question and saw your answer...
I figured out how to do what you were looking for over the weekend. I am not sure if it is good practice to use the description field but here is a link to the article that helped me... http://www.norio.be/blog/2008/10/displaying-taxonomy-term-description-to... JM
This is a little off of the main topic, but you mentioned that you can use a combination of robots.txt and pathauto to hide those description nodes from search engines and keep them from displaying on the site. Can you point me in the direction of an example that demonstrates how to do this? Thanks for the wonderful podcasts. I'm still a newbie and they are very helpful.
hey Nancy, To hide certain nodes from search engines (which respect robots.txt) simply set any node types you want to hid to have a url of something like /hidden/[node-title] then, in robots.txt (in the root) add /hidden to the disallowed list. Hope that helps.
I love your podcasts, but this is pure genius! Thank you so much, you explain difficult subjects with such ease that it makes it so easy for us themers to pick up, understand and implement. I've been so frustrated with the default taxonomy pages for so long, it's like a whole new Drupal world has just been opened up to me! Thanks again for a great tutorial and keep em coming!
I believe your view embedding code can be simplified as: print views_embed_view('taxonomypages', 'block_1', $tids); see: http://api.lullabot.com/views_embed_view but, because this view embed code does not check the access setting from the view, I created a new function print insert_view('taxonomypages', 'block_1', $tids); the function can be found at the bottom of this module code: http://drupal.org/files/issues/insert_view.module.txt and should be part of the next release of the insert_view module
Hey Pasqualle, The code you show here is what I used to use as well, up until about 6 months ago...Then I read this comment by merlinofchaos (views author) that says to use the method shown in this screencast. But just now, I read further down this post where he seems to contradict himself in comment #13 on that issue. So...to be honest, now I'm confused... EDIT: Ok, it looks like now merlin is saying that views_embed_views is the correct method! See his comment to my question here. So, while what's shown in the screencast works, it seems that Pasqualle is now correct and we should be using views_embed_view() instead. Thanks for questioning this!
Bob, Great podcast! One suggestion for those looking to grab description text from the term would be to consider using Node Auto Term (NAT) module. This creates a taxonomy term in a specified vocab for every node of a specified type. What's extra cool is that it can sync the body field of the node with the description of the taxonomy term. So, you can grab the term description directly from the corresponding node... which can feature all the extra fields you may require.
Can you tell me the editor you are using. Its great bc editor and the viewer are side by side,,, thx
Bob, your a champion you have saved me alot of head aches Looking forward to more great podcasts
Awesoem screencast! What would I name my .tpl.php files if I wanted a different one for each vocabulary? Paul
Is anyone able to provide any ideas for my question above? (@vibe7 The editor he is using is Coda (http://www.panic.com/coda/)
Great job. I was searching for this for a long time, but it's not working for me. I have drupal 6.12 and views 6.2.6
Just don't get it. I followed the screencast exactly, but it's not working for me. I have Drupal 6.13 and Views 6.x-2.6. I see two main reasons why it's not working: 1. Wrong file name. It should be page-taxonomy.tpl.php or page-taxonomy-term.tpl.php. Well, correcting filename is not a big deal. 2. Variable $tids is not defined. And this is a real problem. At least for me. I just get list of all pages, regardless of taxonomy terms they use. Best regards! Peter
Thanks for the screencast first of all. Second, you could do the same, with a much better performance impact by using the theme function provided by taxonomy in your template.php like this: function MYTHEME_taxonomy_term_page($tids, $result) { $output = ''; // Only display the description if we have a single term, to avoid clutter and confusion. if (count($tids) == 1) { $term = taxonomy_get_term($tids[0]); $description = $term->description; // Check that a description is set. if (!empty($description)) { $output .= ''; $output .= filter_xss_admin($description); $output .= ''; } } // we use this view to render the content rather than normal taxonmy behaviour $view = views_get_view('MYVIEW'); $output .= $view->execute_display('MYDISPLAY', $tids); return $output; } This way, not only do you gain speed by avoiding tpl file, but also you avoid a call to taxonomy_render_nodes($result); that the module does by default, and that you are not using. See the original theme function to see what I mean. If you dont care for taxonomy term descriptions, you could just remove the first part of the code, and gain a bit more performance that way.
One quick question: When creating an introduction for your taxonomy page, why wouldn't you want to assign a taxonomy to it (instead of using CCK taxonomy)?
Hey Bob, thanks for another awesome podcast! I just wondered if I could realize something like this with the mentioned method: http://www.bildercache.de/anzeige.html?dateiname=20090812-182518-113.png That's the detail site for a product which the users can wright test reports for. At the top of the page you can see some product information which will be manually created by me. At the bottom there should be the teasers for the test reports (if there are any available). The test reports refer to the product via taxonomy (Hierarchical Select). Is there the possibility to include a kind of variable view right in a node.tpl.php so that I'd just have to create a new node with my product information and the test reports are added automatically as soon as the users wright them. Thanks, Nico
OK, after watching the podcast a few times I understood it and could realize what I described in the post before. Just one more question: How could I list those taxonomy pages so that there's for example a page called "manufacturer XYZ" on which the user can find a views like list of the taxonomy pages (in my case the product sites). Instead of this it would also be cool if the user could use the taxonomy select box (hierarchical select) to navigate to the product sites It would be great if you've got a solution for this problem. Greets, Nico
Really nice Podcast, though I seem to be having difficulties. Latest release of Drupal and Views as of Aug 20. I'm having the same/similar problem as Peter. I have a state vocab with terms for every state. When I click on the FL term, it displays all nodes with any term (so, even if something is tagged CA instead of FL it still displays). However, when I click on CA, GA, etc; no nodes are displayed. In essence, only 1 term is displaying all nodes where the other 49 terms display no nodes. FL is also the 1st term I entered for the state vocab. Coincidence? I am assuming this is somehow related. My argument settings look like this:
  • Action to take if no argument: Hide view / Page not found (404)
  • Validator: Taxonomy Term, Vocabulary: State
  • Argument Type: Term ID
Any ideas/suggestions would be great. Thanks!
For anyone that read my post above... The problem I was having here is that my argument was incorrectly set as Taxonomy: Vocabulary ID, instead of Taxonomy: Term ID. Thanks again.
Bob and the board- Any help would greatly be appreciated. I have Views 2 and Drupal 6 and am call in taxonomy into the template file with: <?php print views_embed_view('TaxonomyTerms', 'block_1', $tids); ?> I have also tried this as per your screen cast. <?php $view = views_get)view('taxonomyterms'); $display = $view->execute_display('block', $tids); print $display['content']; ?> I double checked to make sure my Arg was set to Taxonomy Term ID, and it is. The page returns all of the items. The arg does not return with a filtered list. Thanks for the time and help. Bob and Mustardseed keep up the great work!!! Donations to come.
@ Anthony, I am having the same problem. The page returns all of the taxonomy items. The arg does not return with a filtered list for the page. I am using the same views_embed_view, were you able to resolve the problem? I am using Drupal 6.13 with Views 6.x-2.6 Is there a way to use "Drupal for Firebug" to examine the Arguments? Any help would be great.
@ Paul I am also trying to use a tpl.php for a single vocab as well referencing http://drupal.org/node/277991 I don't have everything working yet, and there might be mistakes but here it is my work in progress so far. From my template.php, function MYTHEME_preprocess_page(&$vars, $hook) { if(arg(0) == 'taxonomy' && arg(1) == 'term') { $taxo_term = taxonomy_get_term(arg(2)); $vars['taxonomy_term_description'] = filter_xss_admin($taxo_term->description); $vars['taxonomy_term_vid'] = filter_xss_admin($taxo_term->vid); if($taxo_term->vid == 9) { $suggestions = array('page-taxonomy-vocab-catalog'); $vars['my_vocab_content'] = views_embed_view('taxonomypages', 'page_1', $tids); } else { $suggestions = array('page-taxonomy-vocab-' . $taxo_term->vid); } $vars['template_files'] = array_merge($vars['template_files'], $suggestions); } I just tested and the tpl (page-taxonomy-vocab-catalog.tpl.php) seems to be working with my catalog which is vocabulary 9, but I am having issues with the $tids not filtering my embed_view, it works when I preview my view in views2 by not when I view the vocab terms.
Reference http://drupal.org/node/246742 Please note to use preview() rather than execute_display() #13 merlinofchaos - August 18, 2008 - 01:58 Never ever ever use execute_display() to embed a view. Always use preview(). See views_embed_view() for the canonical example. view::execute_display() should only be used where the display handler was intended to be used. i.e, a 'page' display should only use execute_display via a proper page callback, and a 'block' display should only use execute_display via hook_block.
Thanks for the reference Dave. Still not perfect yet but at least it gives me a term with the arguments now. here is an update of my page-taxonomy-vocab-catalog.tpl.php <?php // A block with a summary and count of the terms, links are an issue $view_S = views_get_view('taxonomypages'); $view_S->set_arguments(array('FALSE')); $display_S = $view_S->preview('block_2'); print $display_S; // A block that is now filtered on the argument which is a taxonomy term $view_B = views_get_view('taxonomypages'); $view_B->set_arguments(array(arg(2))); $display_B = $view_B->preview('block_1'); print $display_B; ?>
I'm loving this podcast, and trying to apply it to a site. The only thing not working for me is getting the results to filter based on Taxonomy Term ID. It looks like others had the same problem, but I don't understand how to fix it while keeping everything else Bob did the same. Are we just doing something wrong, or is there really an issue with that? Doesn't viewing the taxonomy term page automatically include a Term ID? I think I'm copying the podcast pretty exact.
http://drupalmodules.com/module/taxonomy-views-integrator Just saw this beta module which allows selective overriding of taxonomy terms and/or vocabulary with the view of your choice. I haven't had time to try the module yet.
@Dan M I had the same filter issue, couldn't figure out how to make use of the Term ID that taxonomy term page is automatically including. I just used arg(2) see my http://mustardseedmedia.com/podcast/episode31#comment-857 comment on September 9, 2009. If anyone know how to inspect the args that were automatically included using drupal for firebug let me know? Drupal for Firebug http://drupalforfirebug.chapterthree.com/
(I knew this had to be my mistake) - I copied the code Bob was using to embed his View but as you watch the podcast, he changes it to use the Taxonomy Term ID. He first pastes in code that includes this: $view=views_get_view('taxonomypages'); $myargs=array(); $display=$view->execute_display('block_1', $myargs); print $display['content']; and THEN shows you how to change it to this: $view=views_get_view('taxonomypages'); $display=$view->execute_display('block_1', $tids); print $display['content']; That is why I was getting the wrong results. Stupid mistake. Podcast is spot on. Thanks!
Cool site, love the info.
I have a slight problem and was wondering if anyone could help me here. I have a catalog that Ubercart has created. The only problem is, it shows products that are out of stock stock, so i decided to make my own view. So i create one with the arguments of:
  1. Taxonomy: Term ID (with depth)
  2. Taxonomy: Term ID depth modifier
  3. Taxonomy: Term
      How It Works So it works like this: /term/television (WORKS: lists all tv's + any products with the grandparent term of television) /term/television/sony (NOT WORK: Does not show anything) /term/television/rerg4wey/sony (WORKS: now this shows only the the sony tvs, which is correct. However, argument 2 can be anything- which i do not want) The problem The problem is that SONY should be in argument 2. I think VIEWS has taken the 'depth' modifier to be argument 2. Is there a possible solution for this?
Very nice and helpful. I would like only to do the part of adding content before the default content. How do I retrieve the default content - the one which is displayed if taxonomy_term_page.tpl.php would not been added? I have tried @content and $body - none brought the data. Thanks!
Love your podcasts even though you are talking faster than a Volvo P18, its really easy to follow. Never get stuck on unwanted details. Keep up the good work. This taxonomy stuff really rocks! Anders
Awesome! I spent my entire day looking for a flexible solution like this. I was able to use your technique to create a taxonomy catalog that can display both child terms and nodes on the same page using 2 different views. My taxonomy-term-page.tpl.php code looks like this: <?php $view_terms=views_get_view('product_categories'); $display=$view_terms->execute_display('block_1', $tids); print $display['content']; $view_nodes=views_get_view('products'); $display_nodes=$view_nodes->execute_display('block_1', $tids); print $display_nodes['content']; ?> The 'product_categories' is a taxonomy view that displays all child terms based on the parent ID view. The 'products' is a node view that displays any nodes associated with that product category. I thought something like this would be straight forward using taxonomy. I was mistaken. Thanks for the help!