Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By ypay on
The block should be visible only for this specific content type (event) and if the cost is not $0 and the (current date - event date > 48 hours). Using the below php snippet, any ideas?
Content Type=event
CCK Cost Field=cckfield_event_costs
CCK Date Field=cckfield_event_date
$return = FALSE;
if ( (arg(0) == 'node') && is_numeric(arg(1)) ) {
$nid = arg(1);
$node = node_load($nid);
$type = $node->type;
$cost = $node->cckfield_event_costs;
$eventdate = $node->cckfield_event_date;
if ( ($type == "event") && ($cost != "$0 - Free")) {
$return = TRUE;
}
}
return $return;
Comments
You should
You should use:
$node->cckfield_event_costs[0];
Help
Thank you for your suggestion. However it outputs "Array" and not "$0 - Free". Also any pointers on the date comparison? Appreciate it...
Try $cost = $node->cckfield_event_costs[0]['value'];
Perhaps you need to specify the value you're assigning to the $cost variable...I think this may get you closer:
$cost = $node->cckfield_event_costs[0]['value'];
This works...
Using the dateDiff function this works...hope it helps someone with a similar need can modify the below to suit their particular needs.
Nice work!
Thanks for the code snippet. It may come in handy.
one doubt!
could you please tell me where i will put thiscode snippet?
Thanks?