try:
$alt = get_post_meta($thumbnail_image[0]->ID, '_wp_attachment_image_alt', true);
It’s a typo $thumb_id
has a value, and $thumbnail_id
has never been set!
$thumb_id = get_post_thumbnail_id($post->id);
//Uncomment to show the thumbnail alt field
//$alt = get_post_meta($thumbnail_id, '_wp_attachment_image_alt', true);
Should be:
//Uncomment to show the thumbnail alt field
//$alt = get_post_meta($thumb_id, '_wp_attachment_image_alt', true);
HTH
David
thanks for finding that typo.
Here is another use for the function: adding linked photo credits. See it here in action: Newsprint Theme.
To do this I used the plugin Media Custom Fields. This plugin is buggy, but if you read the forum posts on it, your can fix it.
Then I made a media custom field called Credit, and one called Credit URL. This keeps everything semantic.
I used the following function:
function the_post_thumbnail_credit() {
global $post;
$thumb_id = get_post_thumbnail_id($post->id);
$args = array(
'post_type' => 'attachment',
'post_status' => null,
'post_parent' => $post->ID,
'include' => $thumb_id
);
$thumbnail_image = get_posts($args);
if ($thumbnail_image && isset($thumbnail_image[0])) {
$credit = get_post_meta($thumb_id, 'tqmcf_photo-credit', true);
$crediturl = get_post_meta($thumb_id, 'tqmcf_photo-credit-url', true);
if(count($crediturl)) echo '<p class="photocredit"><a href="'. $crediturl . '">';
if(count($credit)) echo $credit;
if(count($crediturl)) echo '</a></p>';
}
}
Both credit and link are added to the loop with this:
the_post_thumbnail_credit()
Nice column layout, did you use post classes?
I used them recently for different layouts per category, you might find something handy as it only uses one WordPress post image size for all seven different layouts.
Photography and news like your theme needs a clean simple look, with dashed borders, here is the twenty eleven child photo/magazine theme!
HTH
David
Thanks, David. I have not yet implemented post classes in this one.. I’m not sure they will be needed.