Hi,

I am trying to create a content type that displays different images based on conditions set in a CCK Computed field. An example for this may be displaying different images for different months or different images for different statuses set by another field. The images are stored in the 'files' directory and the if statement is working as expected, I tested it by sending text to the output instead of the image.

$t=getdate();
$today=date('Y-m-d',$t[0]);
$due_date = $node->field_due_date[0]['value'];

if ($due_date < $today) {
$node_field[0]['value'] ="Red, due date is - " . $due_date;
} else {
$node_field[0]['value'] = "Green, due date is - " . $due_date;
}

Can anyone help me replace the '$node_field[0]['value'] ="Red, due date is - " . $due_date' row with a statement that will output an image named red.gif?

Comments

r0n3n’s picture

Any ideas anyone?

mooffie’s picture

change the conditional to:

if ($due_date < $today) {
  $node_field[0]['value'] = 'due';
} else {
  $node_field[0]['value'] = 'ok';
}

(In other words, we want the field to hold a keyword that describes the status of this library book(?))

Then, in the 'Display Format' box (make sure 'Display this field' is checked), do:

if ($node_field_item['value'] == 'due') {
  $display = '<img src=.... />';
} else {
  $display = '<img src=.... />';
}