WordPress.org

Forums

Writr
[resolved] Featured image not displaying (10 posts)

  1. kevintayloruk
    Member
    Posted 1 year ago #

    Using Writr 1.0.7 and a fresh install of wordpress I can't seem to make featured images appear.

    I've set the post type to an image, added an image to the post then set a featured image and it doesn't display the featured image.

    Any ideas?

    I'm only just setting up my photo blog so it's a little messy and I'm worrying about content before releasing it to the wild but it's here at http://www.okiedokie.co.uk/?p=4 (has featured image set and I won't change that post for a while if you want to take a look at any code).

  2. Hi Kevin, featured images on posts in Writr require the post to use the Standard post format. Could you try changing your post format from Image to Standard format? The featured image should appear once you do that.

    Let me know how it goes!

  3. sgonzaga
    Member
    Posted 1 year ago #

    Just confirming that you do have to switch your post format to Standard if you want to see the featured image.

    Which leads me to my question: is it possible to have the featured image appear when using other post formats? My site (http://betterworkph.com) will be featuring audio from our podcast and I might decide to include a featured image to it. Let me know if this is possible and how.

    Thanks!

  4. Hi there, these are the lines (19-25) in content.php that are restricting the featured image to only certain post formats:

    <?php if ( '' != get_the_post_thumbnail() && '' == $format ) : ?>
       <div class="entry-thumbnail">
         <a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( sprintf( __( 'Permalink to %s', 'writr' ), the_title_attribute( 'echo=0' ) ) ); ?>" rel="<?php the_ID(); ?>">
       <?php the_post_thumbnail( 'featured-image' ); ?>
       </div><!-- .post-thumbnail -->
    <?php endif; ?>

    You can remove (or comment out) the if statement around the featured image code to remove the condition. The if statement is the first and last line above - lines 19 and 25. (Keep in mind that line numbers may differ if you've made any other edits to this file.)

    I tested this on my end and it works to display the featured image on the main blog page no matter what post format is selected - audio, quote, image, etc.

    As always, the best way to make changes to a theme is to use a child theme, so your tweaks won't be overwritten when updating the theme. Here are some guides in case you haven't made one before:

    http://codex.wordpress.org/Child_Themes
    http://op111.net/53/
    http://vimeo.com/49770088

    Let me know how it goes.

  5. sgonzaga
    Member
    Posted 1 year ago #

    I followed your instructions, but the featured image still doesn't appear after removing those lines of code. This is what my child theme's content.php looks like:

    <?php
    /**
     * @package Writr
     */
    $format = get_post_format();
    $formats = get_theme_support( 'post-formats' );
    ?>
    
    <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    	<header class="entry-header">
    		<?php
    			if ( 'link' == $format ) :
    				the_title( '<h1 class="entry-title"><a href="' . esc_url( writr_get_link_url() ) . '" rel="bookmark">', '</a></h1>' );
    			else :
    				the_title( '<h1 class="entry-title"><a href="' . esc_url( get_permalink() ) . '" rel="bookmark">', '</a></h1>' );
    			endif;
    		?>
    
    		<?php if ( is_sticky() && is_front_page() && ! is_paged() ) : ?>
    			<span class="entry-format-badge genericon genericon-star"><span class="screen-reader-text"><?php _e( 'Sticky', 'writr' ); ?></span></span>
    		<?php elseif ( $format && in_array( $format, $formats[0] ) ) : ?>
    			<a class="entry-format-badge genericon genericon-<?php echo $format; ?>" href="<?php echo esc_url( get_post_format_link( $format ) ); ?>" title="<?php echo esc_attr( sprintf( __( 'All %s posts', 'writr' ), get_post_format_string( $format ) ) ); ?>"><span class="screen-reader-text"><?php echo get_post_format_string( $format ); ?></span></a>
    		<?php else : ?>
    			<span class="entry-format-badge genericon genericon-standard"><span class="screen-reader-text"><?php _e( 'Standard', 'writr' ); ?></span></span>
    		<?php endif; ?>
    	</header><!-- .entry-header -->
    
    	<?php if ( is_search() ) : // Only display Excerpts for Search ?>
    	<div class="entry-summary">
    		<?php the_excerpt(); ?>
    	</div><!-- .entry-summary -->
    	<?php else : ?>
    	<div class="entry-content">
    		<?php the_content( __( 'Continue reading', 'writr' ) ); ?>
    		<?php
    			wp_link_pages( array(
    				'before' => '<div class="page-links">' . __( 'Pages:', 'writr' ),
    				'after'  => '</div>',
    			) );
    		?>
    	</div><!-- .entry-content -->
    	<?php endif; ?>
    
    	<?php if ( 'post' == get_post_type() ) : // Hide meta for pages on Search ?>
    	<footer class="entry-meta">
    
    		<ul class="clear">
    			<?php writr_meta(); ?>
    		</ul>
    
    	</footer><!-- .entry-meta -->
    	<?php endif; ?>
    </article><!-- #post-## -->

    Let me know if I missed anything or if you need to see the actual content.php file.

  6. sgonzaga
    Member
    Posted 1 year ago #

    I re-checked your post and realized that you only said to remove line 19 and 25.

    I tried that as well but it still doesn't work when you click on the actual post. I'm referring to http://betterworkph.com/hello-world/.

    See code:

    <?php
    /**
     * @package Writr
     */
    $format = get_post_format();
    $formats = get_theme_support( 'post-formats' );
    ?>
    
    <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    	<header class="entry-header">
    		<?php
    			if ( 'link' == $format ) :
    				the_title( '<h1 class="entry-title"><a href="' . esc_url( writr_get_link_url() ) . '" rel="bookmark">', '</a></h1>' );
    			else :
    				the_title( '<h1 class="entry-title"><a href="' . esc_url( get_permalink() ) . '" rel="bookmark">', '</a></h1>' );
    			endif;
    		?>
    
    		<div class="entry-thumbnail">
    			<a>" title="<?php echo esc_attr( sprintf( __( 'Permalink to %s', 'writr' ), the_title_attribute( 'echo=0' ) ) ); ?>" rel="<?php the_ID(); ?>">
    				<?php the_post_thumbnail( 'featured-image' ); ?>
    			</a>
    		</div><!-- .post-thumbnail -->
    
    		<?php if ( is_sticky() && is_front_page() && ! is_paged() ) : ?>
    			<span class="entry-format-badge genericon genericon-star"><span class="screen-reader-text"><?php _e( 'Sticky', 'writr' ); ?></span></span>
    		<?php elseif ( $format && in_array( $format, $formats[0] ) ) : ?>
    			<a>" href="<?php echo esc_url( get_post_format_link( $format ) ); ?>" title="<?php echo esc_attr( sprintf( __( 'All %s posts', 'writr' ), get_post_format_string( $format ) ) ); ?>"><span class="screen-reader-text"><?php echo get_post_format_string( $format ); ?></span></a>
    		<?php else : ?>
    			<span class="entry-format-badge genericon genericon-standard"><span class="screen-reader-text"><?php _e( 'Standard', 'writr' ); ?></span></span>
    		<?php endif; ?>
    	</header><!-- .entry-header -->
    
    	<?php if ( is_search() ) : // Only display Excerpts for Search ?>
    	<div class="entry-summary">
    		<?php the_excerpt(); ?>
    	</div><!-- .entry-summary -->
    	<?php else : ?>
    	<div class="entry-content">
    		<?php the_content( __( 'Continue reading', 'writr' ) ); ?>
    		<?php
    			wp_link_pages( array(
    				'before' => '<div class="page-links">' . __( 'Pages:', 'writr' ),
    				'after'  => '</div>',
    			) );
    		?>
    	</div><!-- .entry-content -->
    	<?php endif; ?>
    
    	<?php if ( 'post' == get_post_type() ) : // Hide meta for pages on Search ?>
    	<footer class="entry-meta">
    
    		<ul class="clear">
    			<?php writr_meta(); ?>
    
    	</footer><!-- .entry-meta -->
    	<?php endif; ?>
    </article><!-- #post-## -->
  7. I tried that as well but it still doesn't work when you click on the actual post.

    That's right - as I mentioned above, these tweaks "display the featured image on the main blog page no matter what post format is selected." They don't affect the single post view.

    If you also want to change the single post view, you'll need to add content-single.php to your child theme and make a tweak to it as well.

    Look at line 19 in content-single.php:

    <?php if ( '' != get_the_post_thumbnail() && '' == $format ) : ?>

    Remove this part:

    && '' == $format

    ...so that line looks like:

    <?php if ( '' != get_the_post_thumbnail() ) : ?>

    That should do the trick - let me know!

  8. kevintayloruk
    Member
    Posted 1 year ago #

    Thanks Kathyrn, makes sense!

    Kevin

  9. sgonzaga
    Member
    Posted 1 year ago #

    Awesome. It worked! Thanks Kathryn for your help. :)

  10. You're welcome, both!

Topic Closed

This topic has been closed to new replies.

About this Theme

About this Topic