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 much of a php-noob but have this idea of a loop for my site. I have the idea behind it but maybe you have an idea how to put this into code:

$customfield = get_specific_customfield

if $custom-field is = not empty
echo 'custom-field-input" class="'

else

echo '`<?php echo $thumbnail_src[0]; ?>" class="fancybox`'

(I have to integrate the fancy-box stuff to control how the input will be displayed)

share|improve this question
2  
whats the question? –  Bainternet Aug 15 '11 at 11:29
    
»...maybe you have an idea how to put this into code« –  juliusk Aug 15 '11 at 16:10

1 Answer 1

up vote 0 down vote accepted

To get a value of a single custom field use

<?php
    $post_id = $post->ID;
    $key = 'value';  // change value to what custom field you are looking for
    // To retrieve only the first value of given key
    $customfield = get_post_meta($post_id, $key, 'true');
    // To use as default
    $customfield = get_post_meta($post_id, $key);
    // Then check what you got
    if($customfield)
?>
    <img class="thumb" src="<?php echo get_post_meta($post_id, $key, true) ?>" alt="<?php the_title(); ?>" />
<?php
    else

    echo 'whatever you want to show by default';
?>

For further reading goto codex

Hope it helps you

share|improve this answer

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.