2017-01-26 44 views
0

我在single.php中使用get_template_part('content');。功能the_post_thumbnail('large-thumbnail');功能完美地顯示縮略圖。但它不會在content.php中顯示is_single()函數。is_single()函數不顯示縮略圖圖像

content.php代碼:

<?php 
if(is_single()){ 
the_post_thumbnail('large-thumbnail'); 
the_content(); 
}else{ 
the_post_thumbnail('small-thumbnail'); 
echo get_the_excerpt(); 
?> 
<a href="<?php the_permalink(); ?>">Read more&raquo;</a> 
<?php } ?> 

的single.php:

<article> 
     <div class="single_post_content"> 
      <h5><?php the_title(); ?></h5> 

      <?php 
      get_template_part('content'); 
      ?> 
     </div> 
    </article> 

回答

0

我想你忘了寫WP循環在你的single.php文件。按照這個代碼,

<?php while (have_posts()) : the_post(); 
    get_template_part('content');  
endwhile; wp_reset_postdata(); ?> 

the_post_thumbnail()不工作了WP循環的,所以叫環路之間的get_template_part()函數。可能現在它會解決你的問題。