我无法在wordpress主页中显示自定义字段。 这是代码(完全工作,除了显示自定义字段的部分)
<?php
$thumbnails = get_posts('numberposts=3&cat=3');
foreach ($thumbnails as $thumbnail) {
if ( has_post_thumbnail($thumbnail->ID)) {
echo '<div class="contest-home"><a href="' . get_permalink( $thumbnail->ID ) . '" title="' . esc_attr( $thumbnail->post_title ) . '">';
echo get_the_post_thumbnail($thumbnail->ID, 'medium', array('class'=> "blur") );
echo '</a>';
echo '<h2><center>' . esc_attr( $thumbnail->post_title ) . '</center></h2>';
echo get_post_meta($post->ID, "RiassuntoHome", true);
echo '<p><b>Giorni restanti:</b> 30 giorni';
echo '<br><b>Premio:</b> 10.000 euro';
echo '</p><center><a class="st-btn slarge st-btn-green st-btn-slarge" href="' . get_permalink( $thumbnail->ID ) . '">Invia la Tua Idea</a></center></div>';
}
}
?>
<?php echo '<div class="clearfix"></div></div>' ?>
答案 0 :(得分:1)
对象为$thumbnail
,而不是$post
:
echo get_post_meta($thumbnail->ID, "RiassuntoHome", true);