I have tested several menu-modules, but they don't really work like I want them to.

I wrote my own block that checks ?q=... and shows a menu when it matches with a table I created in the database.

works fine, but now I want to know how I can see if a node is under a "vocabulary" in the taxonomy

e.g.
Introduction (node n° 10)
--Lalalala (node n° 14)
--Tralalala (node n° 16)
Where in the database can I find that node n° 16 is a therm of the voc Introduction?

a query would be fine, not one of the thousands functions in drupal :(

thanks

Comments

herbivorous’s picture

How did you check ?q= ? I just had to find my own workaround for that, and it wasn't necessarily pretty.

I don't understand exactly what you are trying to do. I know there is a function taxonomy_get_parent, which I haven't used but which I think would produce Introduction if you know the tid for Tralalala.

The block that I just wrote looks at the displayed node and sees what Taxonomies are related. It then displays a block for each. Eg:

Author: Dr. Seuss

Dr. Seuss wrote many children's books (short snippet from tax desc.)

Cat in the Hat
Butter Battle Book
Oh The Places You'll Go (it lists up to five most recent articles/publications)

- new block-
Topic: Cats in Hats

(etc.)

I can show you how I did that, though I'm not convinced that that is what you want.

You might also look into the book module -- that seems relevant.

Wang123-1’s picture

I'm trying to do the same thing, I think. I am using xtemplate to display a three column layout. In the left column I call the {blocks} from extemplate.

My problem is that I want to include particular blocks containing menus in the left column for node pages associated with a particular taxonomy item.

Using the core install I can restrict the menus to display on taxonomy pages by limiting the path with a perl expression. But, I cannot figure out how to get a menu block to appear in the left column when a particular node is called.

This seems really simple, but I haven't been able to figure it out. I thought I could do it with taxonomy menu but I can't find examples or good documentation to help me figure it out.

Herbivorous, could you share the block that you wrote? If it does what I think you're suggesting, that is, it compares the node ID with the taxonomy ID and then displays the rest of the block content if it matches, that would be PERFECT.

Any other solutions/suggestions are welcome.

Thanks in advance - W

herbivorous’s picture

Here's what I did. I am learning php and drupal on a "need to know" basis as I go along, so this may not be as fancy or clean as it should be. I think that it needs to be bolstered to deal with null sets -- I've seen a few errors when there are no links to fill a box. Should be an easy fix.

Vocab 1 is Authors, 2 is story type, 3 is topic which not all nodes have, and 4 is project within my organization which created the content. There could be more than one author for a story -- code is set up to create a block for each. If a node has a topic, the code will create a block for the topic, then one for each author. If no topic, the authors come first, then project-related links.

I can try to help you apply it to your own sites if you can't navigate the challenges.

(Oh, it is meant to be pasted into custom block set to display only in /node/view.)


// this was the only way I found to get the current page node id
$mynid = arg(2);

$story_type = taxonomy_node_get_terms_by_vocabulary($mynid, 2);
$topic = taxonomy_node_get_terms_by_vocabulary($mynid, 3);

//define types of content valid to appear in block
$display_types = array ("IPS in the News","Media","Commentary","Report","Publication");

//establish precedence of menus -- if a topic, topic then author
//if no topic, authors then project

if ($topic) {
$menu_seq = array (3, 4);
} else {
$menu_seq = array (4, 1);
}

$story_limit = 5; //max links for each -- could be variable based on $menu_seq

foreach ($menu_seq as $current_voc) {

	$terms = taxonomy_node_get_terms_by_vocabulary($mynid, $current_voc);
	$output= "";
				
	
	foreach ($terms as $term) {
		$tax = array ("str_tids" => "$term->tid,$term->tid", "tids" => array($term->tid,$term->tid), "operator" => "or");
		
		switch ($current_voc) {
			case 1:
   				$subject = "Project: ";
   				break;
			case 3:
   				$subject = "Topic: ";
   				break;
			case 4:
   				$subject = "Author: ";
   				break;
			}

		$subject = $subject." $term->name";

		$result = taxonomy_select_nodes(array2object($tax), 0);

		$temp_index = 1; 
		
		while ($node2 = db_fetch_object($result)) {
  			
			$term2 = array_pop(taxonomy_node_get_terms_by_vocabulary($node2->nid, 2));

			if (in_array($term2->name,$display_types) && !($node2->nid == $mynid) && $temp_index<=$story_limit){
				$output[] = l($node2->title, "node/view/". $node2->nid);
				$temp_index ++;
			}
		}

	//toss in description	
		
	$desc = "<p>$term->description</p>";
		
	//create link to taxonomy page
	
	switch ($current_voc) {
			case 1:
   				$more = "More from ";
   				break;
			case 3:
   				$more = "More on ";
   				break;
			case 4:
   				$more = "More by ";
   				break;
			}

	$more = "<p><a href=\"?q=taxonomy/page/or/$term->tid\">$more ".$term->name."</a></p>";
	
	global $theme;
	$theme->block($subject, $desc.theme_item_list($output).$more);
}
}

Wang123-1’s picture

Thanks for posting this. I think what I'm trying to do is simpler and I just need to whittle it down to do the following:

For nids 23, 24, and 25 print my html table in the block.

I can't believe you learned this much php on the fly. I am way behind, which might explain why my attempt is not working.

I'll work on modifying yours and post what I come up with.

Any help is appreciated. Thanks again for posting.

herbivorous’s picture

Is your html table static? Always the same content?

And I assume you want it to theme.

You may be able to use the PATH field in the blocks admin to indicated nids 23,24, or 25 -- not sure of the syntax. Brute force solution is to set up three blocks, one for each path &lt;node/view/23&gt; etc., and then slap in your html. You may need to add some CSS styles to get a table in a block to look like the theme, though just wrapping it in &lt;div id="content"&gt; should be enough -- but this is just off the top of my head, and there's a lot of junk up there, so this is probably not QUITE right.

Good luck!

Wang123-1’s picture

Okay, so last night I had a friend/php master over to help me write the code to put in this block. My ISP was down, and since I didn't want to lose the opportunity of the php master looking at this we went to work using the install at www.opensourcecms.com/drupal.

The block worked perfectly, displaying the right content for the right nodes.

So, today, my ISP is back up and I created the same block and it does not appear...at all.

I'm using xtemplate on my site, same as on the site i was using last night.

Here's the code. Any ideas?

$nid = arg(2);
$tax_id = db_result(db_query("SELECT tid FROM {term_node} WHERE nid = %d", $nid));

if ($tax_id == 2 || $tax_id == 4) {
$foo = "This is a Level 2 or 3";
}

if ($tax_id == 23) {
$foo = "This is a Level 4";
$foo = $foo . "<br/>And a Level 5";
}

return t($foo);

Wang123-1’s picture

I think the problem is that my taxonomy includes 7 different vocabularies...therefor creating 7 different entries for each nid in term_node table. I'm reconfiguring the taxonomy now.

Wang123-1’s picture

I am so close to getting this it hurts.

I've reformed my taxonomy so that nodes may only have one tid in term_node table.

If i include the above code in a php block it returns the correct text for each node.

BUT, when i inlcude the following code which says $foo equals some HTML content, the resulting node view has the properly formated HTML above the entire page.

Am I missing something that tells it to return the HTML inside the block when it's called by the theme?

Anyone?

Here's the code:

$nid = arg(2);
$tax_id = db_result(db_query("SELECT tid FROM {term_node} WHERE nid = %d", $nid));

if ($tax_id == 2 || $tax_id == 4) {
$foo = "This is a Level 2 or 3";
}

if ($tax_id == 68) {
$foo = print "<table cellpadding='4' cellspacing='1' border='0' width='100%'>";
print "";
print "<tr class='frameworkColor'>";
print "<td width='100%' class='templateNav'>";
print "<span class='subduedColor'><a href='?q=taxonomy/page/or/24' class='SubNavLinks'>Newsletter Archive</a></span></td>";
print "</tr>";
print "";
print "<tr class='frameworkColor'>";
print "<td width='100%' class='templateNav'><span class='subduedColor'><a href='?q=taxonomy/page/or/25' class='SubNavLinks'>Sign Up for Email</a></span></td>";
print "</tr>";
print "";
print "</table>";
}

return t($foo);

herbivorous’s picture

I haven't got time to really get my head around the problem you're having, but I'd suggest experimenting with something like this

$theme->block($subject, $foo);

for your output.

Just a guess based on a hurried read of your troubles. I do know the pain you mean, though.

Wang123-1’s picture

Thanks to those who made suggestions. I basically had to escape some of the characters and remove all of the 'print' statements and it worked. Thanks again.