要获取单个自定义字段的值,请使用
<?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\';
?>
进一步阅读转到
codex希望对你有帮助