• Resolved Zvabolis

    (@zvabolis)


    I’m having an issue; when one of my posts does not have a featured image non of the post displays (text included).

    This started when I added some code to display the captions for featured images.

    This is the original code which resolves the missing posts issue, but does not display the image captions.

    <?php if ( '' != get_the_post_thumbnail() && ! post_password_required()  &&  ! get_theme_mod('hide_singlethumb') ) : ?>
    		<div class="entry-thumbnail">
    			<a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( sprintf( __( 'Permalink to %s', 'zuki' ), the_title_attribute( 'echo=0' ) ) ); ?>"><?php the_post_thumbnail(); ?></a>
    		</div>

    This is the code I replaced the above code with to display the image captions, but it does not display posts if no featured image is set.

    <?php
    $get_description = get_post(get_post_thumbnail_id())->post_excerpt;
    the_post_thumbnail();
      if(!empty($get_description)){//If description is not empty show the div
      echo '<span class="caption_arrow"></span><br><div class="featured_caption">' . $get_description . '</div>';
      }
    ?>

    I’m working on this site locally, so I can’t provide a url.
    What am I missing here? Can I combine the two code snippets in someway?

    Any advice or help would be much appreciated.

    Thanks,
    Zack

Viewing 1 replies (of 1 total)
  • Thread Starter Zvabolis

    (@zvabolis)

    I figured it out using a combination of the two code snippets.

    This is the original piece of code:

    <?php if ( '' != get_the_post_thumbnail() && ! post_password_required()  &&  ! get_theme_mod('hide_singlethumb') ) : ?>
    		<div class="entry-thumbnail">
    			<a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( sprintf( __( 'Permalink to %s', 'zuki' ), the_title_attribute( 'echo=0' ) ) ); ?>"><?php the_post_thumbnail(); ?></a>
    		</div>

    The amended code is as follows:

    <?php if ( '' != get_the_post_thumbnail() && ! post_password_required()  &&  ! get_theme_mod('hide_singlethumb') ) : ?>
    		<div class="entry-thumbnail">
    			<a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( sprintf( __( 'Permalink to %s', 'zuki' ), the_title_attribute( 'echo=0' ) ) ); ?>"><?php the_post_thumbnail(); ?></a><?php $get_description = get_post(get_post_thumbnail_id())->post_excerpt;
      if(!empty($get_description)){//If description is not empty show the div
      echo '<span class="caption_arrow"></span><br><div class="featured_caption">' . $get_description . '</div>';
      } ?>
    		</div>

    I added everything except the_post_thumbnail(); from my second snippet of code right after the </a> of the original code.

Viewing 1 replies (of 1 total)

The topic ‘Posts not displaying without featured images’ is closed to new replies.