我在wordpress中創建自定義主題,並顯示問題get_the_post_thumbnail();
嘗試了幾種不同的方式,但沒有成功。它迴應'沒有縮略圖',即使有縮略圖Wordpress get_the_post_thumbnail();問題
<?php
/*
* Template Name: Blog Page
*/
get_header(); ?>
<div class="top-image">
<div class="headlines-2">
<h1 class="big">blog</h1>
</div>
</div>
<div id="primary" class="col-md-12">
<main id="main" class="site-main" role="main">
<div class="news">
<?php
$args = array(
'cat' => 9,
'posts_per_page' => '70'
);
// The Query
$the_query = new WP_Query($args);
// The Loop
if (has_post_thumbnail($_post->ID, 'thumbnail')){
$photo = get_the_post_thumbnail($_post->ID, 'thumbnail');
echo '<div class="section1-2singlephoto">' . $photo . '</div>';
}
else {
echo 'no Thumbnail';
}
if ($the_query->have_posts()) {
while ($the_query->have_posts()) {
$the_query->the_post();
echo '<div class="boxed col-md-4">';
echo '<h2 class="titles">' . get_the_title() . '</h2>';
echo '<span class="rule"></span>';
echo '<div class="author-info">'. get_the_date() .'<br>' .
get_the_author_link() .'</div>';
echo get_template_part('template-parts/content', get_post_format()
);
echo "</div>";
}
} else {
// no posts found
}
/* Restore original Post Data */
wp_reset_postdata();?>
</div>
</main><!-- #main -->
</div><!-- #primary -->
<?php
get_footer();
格式代碼 –