I have an Author content_type that I’m switching out for username in articles. The problem is that a story can have multiple authors, and the following code in template.php will only generate the first author. How can I get this to output to be readable as “By John Smith, Jane Doe and Mary Poppins | Feb 19, 2010”?
function mytheme_date($node) {
return t('By !username | !datetime',
array(
'!username' => t($node->field_author[0][view]),
'!datetime' => t($node->field_publish_date[0][view]),
));
}
Please bear in mind that I’m also wanting to use this for views too, so that a node reference will output correctly there too.
Thanks,
Steve
Assuming that the example you’ve given works to output the first author, the most direct solution to get all the authors in a comma-sperated list would be the following:
Then you’d output
$author_listin place of$node->field_author[0][view]A more “Drupal” way of doing it would be to copy modules/cck/theme/content-field.tpl.php to your theme directory, then make a copy of it named content-field-field_author.tpl.php as well. You can then make changes to the new file which would override how the values are displayed for the “author” field specifically. Then you could output themed field_author value wherever you want in a custom node-[node_type].tpl.php file. (You may need to clear cached data via the button on Administer > Site configuration > Performance for the custom templates to be loaded the first time.)
If your view’s “Row style” is set to “Node” then it will use the node and field templates as well. If you have it set to “Fields” then you’ll need to theme the field in the view separately. See your view’s “Theme: Information” for views templates you can override in your theme.
Edit:
Missed the fact that you wanted a natural language list. That takes a bit more, but here’s a Drupalized function that will do just that:
Then, of course, use the following in place of the last line my first code block above:
$author_list = implode_language($authors);