即時通訊複用我在wordpress主題index.php上使用的一些代碼。除了縮略圖(在index.php上工作)之外,一切都有效。 我可以顯示它們。 但是,如果我嘗試通過(has_post_thumbnail())檢查它總是返回false。 哪裏可能是問題?has_post_thumbnail()不工作在頁面
的問題是在以下部分:
if (has_post_thumbnail()) {
$photo = get_the_post_thumbnail($recent['ID'], 'large');
echo '<div class="section1-2singlephoto">' . $photo . '</div>';
}
else {
echo 'no Thumbnail';
}
使用下面的代碼只有將工作:
$photo = get_the_post_thumbnail($recent['ID'], 'large');
echo '<div class="section1-2singlephoto">' .
任何人可以給我一個提示,爲什麼這可能無法正常工作。 我做了一個頁面的頁面模板,並將代碼添加到它。 下面是完整的代碼:
<?php
$args = array('numberposts' => '20',
'offset' => '1'
);
$recent_posts = wp_get_recent_posts($args);
foreach($recent_posts as $recent){
echo '<div class="section1-2single large-12 medium-12 small-12 column">';
echo '<a class="" href="' . get_permalink($recent["ID"]) . '"><h4>' . $recent["post_title"] .'</h4></a>';
echo '<div class="large-12 medium-12 small-12 row">';
echo '<div class="large-2 medium-2 small-2 columns">';
// GET COMMENTS NUMBER
$comments_count = wp_count_comments($recent["ID"]);
echo '<div class=metaDataContainer>';
if ($comments_count->total_comments === 0) {
echo '<i class="fa fa-comment-o commentsNumbre"> 0</i>';
};
if ($comments_count->total_comments === 1) {
echo '<i class="fa fa-comment-o commentsNumbre"> '. $comments_count->total_comments .'</i>';
};
if ($comments_count->total_comments > 1) {
echo '<i class="fa fa-comment-o commentsNumbre"> '. $comments_count->total_comments .'</i>';
};
echo do_shortcode('[mashshare text="'. $recent["post_title"] .'" url="'. get_permalink($recent["ID"]) .' shares="false" align="center" "]');
echo '</div>';
echo '</div>';
echo '<div class="large-10 medium-10 small-10 columns">';
// GET THE THUMBNAIL
if (has_post_thumbnail()) {
$photo = get_the_post_thumbnail($recent['ID'], 'large');
echo '<div class="section1-2singlephoto">' . $photo . '</div>';
}
else {
echo 'no Thumbnail';
}
$content = wpautop($recent['post_content']);
$trimmed_content = wp_trim_words($content, 60, '...');
;
echo '<div class="trimmedContent">' . $content .'</div>';
echo '<a class="button section1-2single-button" href="'. get_permalink($recent["ID"]) .'">weiter</a>';
echo '</div>';
echo '</div>';
echo '</div>';
}
?>
嘗試做'的print_r($照片);'了'if'語句內調試 – staypuftman