I'm trying to write a snippet that will check if an image has been loaded into a cck image field and if not then print a default image. I've been having a look at the user image code in the user module to try get some clues but am a bit stuck on how to apply the same principals to get what i need - i'm afraid this is my first attempt at php coding and i would really appreciate any help!
This is the section of code from the user module that performs the kind of thing i want but i'm not entirely sure how to adapt it:
function theme_user_picture($account) {
if (variable_get('user_pictures', 0)) {
if ($account->picture && file_exists($account->picture)) {
$picture = file_create_url($account->picture);
}
else if (variable_get('user_picture_default', '')) {
$picture = variable_get('user_picture_default', '');
}
if (isset($picture)) {
$alt = t('%user\'s picture', array('%user' => $account->name ? $account->name : variable_get('anonymous', 'Anonymous')));
$picture = theme('image', $picture, $alt, $alt, '', false);
if (!empty($account->uid) && user_access('access user profiles')) {
$picture = l($picture, "user/$account->uid", array('title' => t('View user profile.')), NULL, NULL, FALSE, TRUE);
}
return "<div class=\"picture\">$picture</div>";
}
}
}
and this is the section of code in my cck template that printed out my news image: