[resolved] has_post_thumbnail working for page.php but not single.php (3 posts)

  1. zico12
    Posted 4 years ago #

    Hi, I have a very weird problem with my loop ... am using the roots theme that implements Twitter Bootstrap & working on my own website.

    I have two identical files for the single pages & single posts that asks if there's a featured image .. if so it displays it & if not it just displays the title ... now it's working just fine in the page.php but not in the single.php it always displays the container of the featured image even if it's not set.

    & here's the code

    <?php get_header(); ?>
      <?php roots_header_after(); ?>
      <?php roots_wrap_before(); ?>
      <div class="back-contain">
      <div id="wrap" class="" role="document">
      <div class="container">
      <?php while (have_posts()) : the_post(); ?>
        <?php roots_post_before(); ?>
      	<section class="row page-header">
      		if ( has_post_thumbnail()) {?>
      		<div class="hero-contain span12">
      			<?php the_post_thumbnail('featured-thumb'); ?>
      		<?php } else {?>
      			<h1 class="entry-title span4"><?php the_title(); ?></h1>
      		<?php }
      	<section class="page-content row">
      		<div class="span12">
      			<?php the_content(); ?>
      <?php endwhile; /* End loop */ ?>
       <?php roots_content_after(); ?>
    <?php get_footer(); ?>

    I really have no idea where the problem might be.
    Thanks in advance

  2. Chandan Kumar
    Posted 4 years ago #

    Try the following code under section class "row page-header":

    if ( has_post_thumbnail() ) {
    <h1 class="entry-title span4"><?php the_title(); ?></h1>
  3. zico12
    Posted 4 years ago #

    I just found out the problem, I am using a dummy content plugin that for some reason makes wordpress think all of the posts it created have featured images ... when I set an image then remove it works just fine ...!!

    And thanks chandanonline4u for your reply.

Topic Closed

This topic has been closed to new replies.

About this Topic