Список документов с определёнными терминами



Drupal 5.x

<?php
$taxo_id_arr
= array(2,3,4,5);  // Номера терминов
$taxo_id = join($taxo_id_arr, ',');
$list_no = 100// Количество документов в списке

$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") .
   
'<br /> (Category/ies: ' . join($term_names, ', ') .
   
' - date added ' . format_date($anode->created, 'custom', 'd-m-Y') . ')';
}

if(
count($items)) {
  print
theme('item_list',$items) . '<a href=link>more</a>';
}
?>

Drupal 4.6.x, 4.7.x

<?php
$taxo_id
= "2,3,4,5"// Номера терминов
$list_no =6// Количество документов в списке
$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)) {
 
$items[]= l($anode->title, "node/$anode->nid");
}

if(
count($items)) {
  return
theme('item_list',$items);
}
?>

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
Image CAPTCHA
Copy the characters (respecting upper/lower case) from the image.