Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm using the_post_thumbnail(); (aka featured image) to show a news source logo. If I use that image, I'd like to output the name of the news source. For example:

if the_post_thumbnail is "new-york-times.jpg" echo "New York Times" elseif the_post_thumbnail is "cbs-news.jpg" echo "CBS News" etc...

Any help writing this code is greatly appreciated!

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

If You need title from media use something like this:

<?php
$thumb = get_post(get_post_thumbnail_id());
echo $thumb->post_title;
share|improve this answer
    
Perfect - thank you! –  Ryan Mar 8 '11 at 21:48
add comment

From a quick look at the Codex and some of the source code, I'm not seeing any built-in function that would easily/cleanly get you the file name. I've not played around with the post thumbnail functions much, but if you can figure out in advance the IDs are for each of your thumbnails, then you could try using get_post_thumbnail_id? Something like this pseudo-code perhaps:

<?php
    $thumb = get_post_thumbnail_id();
    switch ($thumb) {
        case "1":
            $source = 'CBS';
            return $source;
        case "2":
            $source = 'New York Times';
            return $source;
    }
?>

And then <?php echo $source ?> where you want that bit of text to display?

share|improve this answer
    
This might be simpler than I thought. Is it possible to output the title of the_post_thumbnail (from the Media Library)? I couldn't find anything in the Codex/forums. –  Ryan Mar 8 '11 at 19:43
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.