Is there any simple way of putting a Similar Content Block comprising of all the node titles of one of the taxonomy term of the page.

I know abt Related Links & Similar entries. . But somehow similar entries are not giving the exact result. . may be due to some complexity of the page.

Example:

Let the current page is attached with 4 taxonomies: tm1, tm2, tm3 and tm4

I want to show all the nodes related with only term tm1

Comments

bwv’s picture

If I understand your question correctly, this should do it... the term number is 7. (PS: There might be other ways of pulling teasers from nodes per a specific term; this one works for me.)

<?php
//put term number immediately below in parens
$taxo_id_arr = array(7);
$taxo_id = join($taxo_id_arr, ',');
$list_no = 15;

$query = "SELECT DISTINCT n.nid, n.title, n.created
  FROM {node} n
  INNER JOIN {term_node} tn ON n.nid = tn.nid
  WHERE tn.tid IN ($taxo_id) AND n.status = 1
  ORDER BY n.created DESC
  LIMIT $list_no";

$sql = db_rewrite_sql($query);
$result = db_query($sql);
$items = array();

while ($anode = db_fetch_object($result)) {

  $term_names = array();
  # gather, into $term_names, all the terms because of which this node was selected:
  foreach (taxonomy_node_get_terms($anode->nid) as $term) {
     if (in_array($term->tid, $taxo_id_arr))
         $term_names[] = $term->name;
  }
  $items[]= l($anode->title, "node/$anode->nid");
}
if(count($items)) {
  print theme('item_list',$items) ;
}

?>

----------------------------------------------------------------------
http://www.bwv810.com/

I am a writer and researcher. In my spare time I build websites with Drupal.
Je peux communiquer en français. / Я могу общаться на русском языке.

nishitdas’s picture

Thanks a lot

But i dont want to specify the term id. . this shd be taken from the url. .ok that i can be done. .
with taxonomy_node_get_terms(arg(1))
but the problem is that its showing terms of diff categories of that node. .i just want terms of only one category. .