I'm trying to create a block that displays a list of nodes, and for each node includes the creation date and the contents of a CCK field (i.e., "field_source_value"). Everything works OK except for the CCK field, which I cannot seem to get into my array ($items[]). Unless there's a problem w/ my SQL query, here's the relevant snippet stripped of my non-functioning CCK-related portion:

  $items[]= l($anode->title, "node/$anode->nid").' ('. format_date($anode->created, 'custom',  'M j Y').')'.***CODE FOR CCK FIELD CONTENTS GOES HERE***;

Seems like it should be simple. Any assistance is appreciated!

Here's the complete block code:

<?php
$taxo_id_arr = array(33,45,46,47,48,49,50,463,510,511,512);
$taxo_id = join($taxo_id_arr, ',');
$list_no = 6;

$query = "SELECT DISTINCT n.nid, n.title, n.created, tn.nid, tn.tid, cfs.nid, cfs.field_source_value
  FROM {node} n
  INNER JOIN {term_node} tn ON n.nid = tn.nid
  INNER JOIN {content_field_source} cfs ON n.nid = cfs.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").' ('. format_date($anode->created, 'custom',  'M j Y').')'.***CODE FOR CCK FIELD CONTENTS GOES HERE***;
}

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

Comments

nevets’s picture

Why not use a view?

gollyg’s picture

generally, after a node loade, single cck fields are stored in a format 'field_fieldname[0]['value']'

try a print_r($node) to see exactly what you are after.

but as the previous comment mentioned - why aren't you using views?