Reputation: 301
I'm working on a Drupal 7 site with an event listing. I've added a date field so the user can specify the date or dates for the event. Now I'm trying to get the date(s) to show in the template. I've tried using this:
<?php print $node->field_event_date['und'][0]['value']; ?>
That works ok, but it only shows one event from the array. I could just repeat that line 10 times and replace the array item number in each one, but I figure there has to be a way to show all the items in an array, whether it's one or ten. Can this be done with PHP or do I need to make a View?
Upvotes: 2
Views: 5930
Reputation: 36956
In PHP terms you're probably looking for a foreach
loop, to iterate over the array and print the values.
In Drupal terms, you'll want to use that with the field_get_items()
function:
$items = field_get_items('node', $node, 'field_event_date');
foreach ($items as $item) {
print $item['value'];
}
For bonus fun, check out EntityMetadataWrapper
s
Upvotes: 3