2

I have created a faculty profile system on our university departments site. Every faculty member is tagged with terms regarding an area of expertise (either in teaching or in research). What I need is to create a view that takes the areas of expertise from a specific faculty members page, and displays the other faculty members that also work within those areas. (but only those areas)

What I have done so far is a view that wants to show ALL the terms on EVERY faculty content type, but I need to have the view filtered somehow based on the specific page that is being viewed. Here is what I have:

http://sustainable.unt.edu/irene-klaver

Here is an example of what I need: http://sustainability.asu.edu/people/persbio.php?pid=188

The faculty nodes are a custom content type (CCK). The view uses Imagecache/Imagefield to use the thumbnails. The terms have their own vocabulary in Taxonomy, specifically for this purpose. I am using Drupal 6.

I have been told by a few that this might not be able to happen with Drupal, and that I have to create some custom php code in my node-faculty.tpl.php file. Since the ASU site aboves developer doesn't use Drupal, they couldn't really help me out much. I find it hard to believe that someone hasn't needed a function that is similar to this before... If anyone can at least point me in the right direction, I would greatly appreciate it!

Thanks!

2 Answers 2

2

Drupal Views can easily do this :)

  1. Create your view and call it "example", and for this example, put Node Title in the Fields.

  2. Add in an argument. Here select Taxonomy: Term ID.

  3. In "Action to take if argument is not present:" select "Provide Default Argument"

  4. There, select "Taxonomy Term ID from URL" and then click "Load default argument from node page, thats good for related taxonomy blocks" and if you want, you can also limit it to specific vocabulary(ies) by clicking "Limit terms by vocabulary" and clicking on the one(s) you want.

  5. Create a "Block Display" and save everything.

  6. Goto your Site Building/Block Admin Page and look for "Views: example" and put it in a region of your theme.

Now, if all is well in the world, that block will appear and will display the titles of all nodes that also have the same taxonomy term as the node it is displayed on. Of course, you will probably want this block displayed only on certain pages, but you can do that in your block UI as well. And of course you'll also probably want to be fancier than just the node title, etc, but there you would include the fields in the specific nodes, etc.

ADDITION:

This is what I see here for a taxonomy term id argument with D6 and Views3:

enter image description here

UGLY SOLUTION:

I was sure there would be a solution to this using just Views, but I can't figure it out for the life of me. Grrrr, I hope someone out there says Duh, this is how you do it. But, if you have the PHP Input Filter enabled, you can create a block that will do this instead of creating a custom module. The PHP Input Filter is UGLY. It should be killed with that dull ax I often use, but here goes:

Add a new block via the blocks UI with this as the block body:

<?php

$node=menu_get_object();

if (isset($node->type) && $node->type=='Faculty') {

  $vid = db_result(db_query('SELECT vid FROM {vocabulary} WHERE name = "Expertise"'));

  if (!empty($node->taxonomy)) {
    foreach($node->taxonomy as $term) {
      if ($term->vid == $vid) {
         print '<div class="expertise-name">' . $term->name . '</div>';
         print '<div class="experts">' . views_embed_view('faculty_expertise_test2', 'default', $term->tid) . '</div>';
      }
    }
  }

}

?>

Make sure you select PHP Code as the Input Filter. Select a Block description and title and save the block. Place it in whatever region you want. Cross fingers and see what happens :) Basically all this does is loop through all taxonomy terms of your Expertise vocabulary in the node shown and then calls the view with that argument. I think I have everything capitalized correctly from your examples, but the key things to customize about are Faculty, Expertise and faculty_expertise_test2, which are your node type, vocabulary and view. If all works, then it's up to you to CSS things to your liking. Hope this helps!

PS I just realized that the view will most probably return the faculty member her/himself but that can be dealt with another day :)

22
  • Jimajamma, first off thank you so much for your quick reply and willingness to help! Secondly, I got to the part where you said click "Load default argument from node page, thats good for related taxonomy blocks"...I'm not seeing anything like that in Views...:( I would add a screenshot but since I'm a new user this website isn't letting me. Do I need a different version? Thanks again for your help!
    – NCocco
    Aug 3, 2012 at 15:31
  • I've added a screen shot of what I see, maybe I am forgetting a click or two in there. I am using D6 with Views 3. Let me know if this helps or if I can be of any more.
    – Jimajamma
    Aug 3, 2012 at 15:44
  • Ok, I'm going to have to ask our Web department to update my Views to 3. They don't let us update/install our own modules, and they don't update things automatically as things come out. When they do the update I'll let you know if this works or not. UGH. I'll keep you updated after it's installed. Thanks again! You're helping out a very confused Drupal novice...:D
    – NCocco
    Aug 3, 2012 at 16:51
  • quite welcome anytime!
    – Jimajamma
    Aug 3, 2012 at 16:54
  • Ok, so I finally got Views 3 and I was able to click on all the new goodies that come with it, except now it isn't working. It's not even displaying the block...help? :)
    – NCocco
    Aug 6, 2012 at 18:42
0

I FOUND AN ANSWER! YAY!

Ok so I figured it out with the help of someone who knows WAY more PHP than I do (and could site me down and actually show me in person), so I'm not going to take credit for this. :) You have to edit the theme of your site, but I actually like this better way better because I can make it pretty with CSS a lot easier. (No more dull axing)

First, create a template file for the content node type (I called mine node-faculty.tpl.php). Then I added this code directly into my template file to call the view:

<?php  

foreach( $node->taxonomy as $tid ) {  
print views_embed_view('faculty_expertise_test2', 'default', $tid->tid);  
}  
?>

AND IT WORKS. Phew! Ok, but I couldn't do it without you. Getting as far as you got me helped someone else help me through the finish line. :)

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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