Nicowillot
Nicowillot

Reputation: 1

Wordpress - Why calling the_post_thumbnail() AFTER get_sidebar() doesn't show anything on my template

I'm actually trying to display the post thumbnail inside the loop just before the content by using the_post_thumbnail(); function.

It works like a charm in anywhere in my page before I call the function

<?php get_sidebar(); ?>

After that impossible to show the post thumbnail. I've tried with

<?php the_post_thumbnail(); ?>

and also

<?php echo get_the_post_thumbnail(); ?> but nothing happens.

Here is my whole code :

<?php
/**
 * The Template for displaying all single posts
 *
 * @package WordPress
 */

get_header(); ?>


<div id="pageHeader" >
  <div id="pageHeader-inner"> <span class="shadow"></span><img src="<?php bloginfo('template_url'); ?>/images/header_01.jpg" /></div>
</div>

<div class="container" id="pageTitle">
        <h1><?php the_title(); ?></h1>
</div>

<!--Begin of content-->
<div class="grey-bg">
  <div class="container">
  <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

    <div class="row">

      <div class="col-sm-3 sidebar">

      <!-- Sub Nav  -->
            <?php if ( is_page() ) { ?>
            <?php
            if($post->post_parent)
            $children = wp_list_pages('title_li=&child_of='.$post->post_parent.'&echo=0'); else
            $children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0');
            if ($children) { ?> 
      <div class="sidebar-module sub-menu">
          <ul>
            <?php echo $children; ?>
          </ul>
       </div>
       <?php } } ?>

<!--Works perfectly till here -->

        <?php get_sidebar(); ?>

<!--Broken till here-->  

      </div>  <!-- /.sidebar --> 

      <div class="col-sm-9">
        <div class="content-main">
        <div class="content white-bg left-stroke <?php echo $post->post_name; ?>">
        <?php if ( has_post_thumbnail() ) the_post_thumbnail(); ?>  
            <?php the_content(); ?>
           <?php endwhile; ?>
            <?php else : ?>
            <div <?php post_class(); ?> id="post-<?php the_ID(); ?>">
                <h1><a href="<?php bloginfo('site_url'); ?>">Not Found</a></h1>
            </div>
            <?php endif; ?>
         </div> <!-- /.content --> 
        </div><!-- /.content-main --> 
      </div>

    </div>
    <!-- /.row -->     
  </div>
  <!-- /.container --> 
</div>
<?php get_footer(); ?>

Thank's a lot for your responses.

Upvotes: 0

Views: 260

Answers (1)

Serge
Serge

Reputation: 35

You are trying to use function the_post_thumbnail() outside WordPress loop. To use this function outside loop you have to specify "post ID". Documentation for this function http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail

For example to get thumbnail for post ID 4 you have to use function with parameter 4 like the_post_thumbnail(4) or store ID in variable.

Upvotes: 2

Related Questions