badget

Biggest Sale! Special Offer!

Get 30% discount on all of our single themes with this coupon code: #30%SALE

Hurry up! *Limited time offer*

Need featured image to display on single posts

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #45976
    david.danaan
    Participant

    Hi,

    I understand that the theme is designed with single.php not displaying the featured image. However, I can’t manually add an image to posts that are displayed in the blog-image-medium template because then the featured image and the second image are both displayed in the blog page view. What code do I need to add to single.php so the featured image is displayed?

    Thanks for your time.

    #45981

    Hi david.danaan,

    Yes the featured image is not displayed on single page. We have designed our theme this way. You can add images on the post editor from media. If you like to display the same featured image on single page then you have to add some code at theme folder -> library-> structure -> content-extension.php on line no 258 inside this functions attitude_theloop_for_single() but adding direct code on the theme, you will get problem while updating to new version. So we always recommended you to create a child theme so that while updating to new version your customized code will not be lost. If you are not familier with child theme then each and every time while you made code customization, the same changes need to make on the theme.

    <?php
    if( has_post_thumbnail() ) {
         the_post_thumbnail();
    } ?>
    

    Thank you!

    #45985
    david.danaan
    Participant

    Thank you. Yes, I am using a child theme. Where inside the function do I need to insert this code? I’ve tried adding it directly inside the loop at line 264, and directly above <?php the_content(); at line 284, with no results. Can you give me more context for where to add it?

    Or do I need to regenerate all my thumbnails, or some additional step?

    Thanks again.

    #45986
    david.danaan
    Participant

    Here is a single post that has a featured image set but not displayed: http://stjamesucc-love.org/july-10-2016/
    and here is the post page on which it appears: http://stjamesucc-love.org/bulletins/

    #45995
    david.danaan
    Participant

    Ok, I figured it out. I found in other topics the explanation for unhooking the function. Here is the code I included in functions.php in my child theme. Note that the thumbnail code is inserted directly before the_content:

    // Unhook 
    function unhook_thematic_functions() {
    // Don't forget the position number if the original function has one
    
    remove_action('attitude_loop_content','attitude_theloop_for_single', 10);
    
    }
    add_action('init','unhook_thematic_functions'); // removes the header content by using hook attitude_header
    
    add_action('attitude_loop_content','attitude_child_theloop_for_single', 10);
    
    // Add function to display featured image in single post template
    
    function attitude_child_theloop_for_single() {
    	global $post;
    
    	if( have_posts() ) {
    		while( have_posts() ) {
    			the_post();
    
    			do_action( 'attitude_before_post' );
    ?>
    	<section id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    		<article>
    
    			<?php do_action( 'attitude_before_post_header' ); ?>
    
    			<header class="entry-header">
        			<h1 class="entry-title">
        				<?php the_title(); ?>
        			</h1><!-- .entry-title -->
      			</header>
    
      			<?php do_action( 'attitude_after_post_header' ); ?>
    
      			<?php do_action( 'attitude_before_post_content' ); ?>
    
      			<?php
    			if ( has_post_thumbnail() ) {
         			the_post_thumbnail(); } ?>
    
      			
      			<div class="entry-content clearfix">
        			<?php the_content();
        			if( is_single() ) {
    						$tag_list = get_the_tag_list( '', __( ', ', 'attitude' ) );
    
    						if( !empty( $tag_list ) ) {
    							?>
    							<div class="tags">
    								<?php
    								_e( 'Tagged on: ', 'attitude' ); echo $tag_list;
    								?>
    							</div>
    							<?php
    						}
    					}
    
                   wp_link_pages( array( 
    						'before'            => '<div style="clear: both;"></div><div class="pagination clearfix">'.__( 'Pages:', 'attitude' ),
    						'after'             => '</div>',
    						'link_before'       => '<span>',
    						'link_after'        => '</span>',
    						'pagelink'          => '%',
    						'echo'              => 1 
                   ) );
                   ?>
      			</div>
    <?php if(get_the_time( get_option( 'date_format' ) )) { ?>
      			<div class="entry-meta-bar clearfix">	        			
        			<div class="entry-meta">
        				<span class="by-author"><?php _e( 'By', 'attitude' ); ?> <a href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ) ); ?>"><?php the_author(); ?></a></span> |
        				<span class="date"><a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( get_the_time() ); ?>"><?php the_time( get_option( 'date_format' ) ); ?></a></span> |
        				<?php if( has_category() ) { ?>
                 		<span class="category"><?php the_category(', '); ?></span> |
                 	<?php } ?> 
        				<?php if ( comments_open() ) { ?>
                 		<span class="comments"><?php comments_popup_link( __( 'No Comments', 'attitude' ), __( '1 Comment', 'attitude' ), __( '% Comments', 'attitude' ), '', __( 'Comments Off', 'attitude' ) ); ?></span> |
                 	<?php } ?> 		          				
        			</div><!-- .entry-meta -->
        		</div>
    
      			<?php 
    
      			do_action( 'attitude_after_post_content' );
    			 }
      			do_action( 'attitude_before_comments_template' ); 
    
             comments_template(); 
    
             do_action ( 'attitude_after_comments_template' );
    
             ?>
    
    		</article>
    	</section>
    <?php
    			do_action( 'attitude_after_post' );
    
    		}
    	}
    	else {
    		?>
    		<h1 class="entry-title"><?php _e( 'No Posts Found.', 'attitude' ); ?></h1>
          <?php
       }
    }
    #45996
    david.danaan
    Participant

    I was wrong. There’s still an issue – this code

    <?php
    			if ( has_post_thumbnail() ) {
         			the_post_thumbnail(); } ?>

    added before the_content is called results in two instances of the post content, one with the featured image, and one below that without the featured image. What am I doing wrong?

    http://stjamesucc-love.org/july-10-2016/

    #45997
    david.danaan
    Participant

    This is code I copied directly from this forum and modified for my function, instructing how to unhook functions:

    / Unhook 
    function unhook_thematic_functions() {
    // Don't forget the position number if the original function has one
    
    remove_action('attitude_loop_content','attitude_theloop_for_single', 10);
    
    }
    add_action('init','unhook_thematic_functions'); // removes the header content by using hook attitude_header
    
    add_action('attitude_loop_content','attitude_child_theloop_for_single', 10);
    
    // Add function to display featured image in single post template

    It is not only calling the_content twice, it’s doing something to the header content and breaking the editing interface so I can’t add new posts – I get an error message ‘cannot modify header’. It also adds a <? to the beginning of each post tag, if that helps. Did I use the wrong action hook for this function? Please advise. I have to remove this modification temporarily from my child theme so I can add new content.

    Thanks.

    #46005

    Hi david.danaan,

    Just copy paste below code in your child theme functions.php

    <?php
    /****************************************************************************************/
    
    if ( ! function_exists( 'attitude_theloop_for_single' ) ) :
    /**
     * Fuction to show the single post content.
     */
    function attitude_theloop_for_single() {
    	global $post;
    
    	if( have_posts() ) {
    		while( have_posts() ) {
    			the_post();
    
    			do_action( 'attitude_before_post' );
    ?>
    	<section id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    		<article>
    
    			<?php do_action( 'attitude_before_post_header' ); ?>
    
    			<header class="entry-header">
        			<h1 class="entry-title">
        				<?php the_title(); ?>
        			</h1><!-- .entry-title -->
      			</header>
    
      			<?php do_action( 'attitude_after_post_header' ); ?>
    
      			<?php do_action( 'attitude_before_post_content' ); ?>
      			<?php
    			if( has_post_thumbnail() ) {
    				$image = '';        			
    	     		$title_attribute = apply_filters( 'the_title', get_the_title( $post->ID ) );
    	     		$image .= '<figure class="post-featured-image">';
    	  			$image .= '<a href="' . get_permalink() . '" title="'.the_title( '', '', false ).'">';
    	  			$image .= get_the_post_thumbnail( $post->ID, 'featured-large', array( 'title' => esc_attr( $title_attribute ), 'alt' => esc_attr( $title_attribute ) ) ).'</a>';
    	  			$image .= '</figure>';
    
    	  			echo $image;
    	  		}
      			?>
    
      			<div class="entry-content clearfix">
        			<?php the_content();
        			if( is_single() ) {
    						$tag_list = get_the_tag_list( '', __( ', ', 'attitude' ) );
    
    						if( !empty( $tag_list ) ) {
    							?>
    							<div class="tags">
    								<?php
    								_e( 'Tagged on: ', 'attitude' ); echo $tag_list;
    								?>
    							</div>
    							<?php
    						}
    					}
    
                   wp_link_pages( array( 
    						'before'            => '<div style="clear: both;"></div><div class="pagination clearfix">'.__( 'Pages:', 'attitude' ),
    						'after'             => '</div>',
    						'link_before'       => '<span>',
    						'link_after'        => '</span>',
    						'pagelink'          => '%',
    						'echo'              => 1 
                   ) );
                   ?>
      			</div>
    <?php if(get_the_time( get_option( 'date_format' ) )) { ?>
      			<div class="entry-meta-bar clearfix">	        			
        			<div class="entry-meta">
        				<span class="by-author"><?php _e( 'By', 'attitude' ); ?> <a href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ) ); ?>"><?php the_author(); ?></a></span> |
        				<span class="date"><a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( get_the_time() ); ?>"><?php the_time( get_option( 'date_format' ) ); ?></a></span> |
        				<?php if( has_category() ) { ?>
                 		<span class="category"><?php the_category(', '); ?></span> |
                 	<?php } ?> 
        				<?php if ( comments_open() ) { ?>
                 		<span class="comments"><?php comments_popup_link( __( 'No Comments', 'attitude' ), __( '1 Comment', 'attitude' ), __( '% Comments', 'attitude' ), '', __( 'Comments Off', 'attitude' ) ); ?></span> |
                 	<?php } ?> 		          				
        			</div><!-- .entry-meta -->
        		</div>
    
      			<?php 
    
      			do_action( 'attitude_after_post_content' );
    			 }
      			do_action( 'attitude_before_comments_template' ); 
    
             comments_template(); 
    
             do_action ( 'attitude_after_comments_template' );
    
             ?>
    
    		</article>
    	</section>
    <?php
    			do_action( 'attitude_after_post' );
    
    		}
    	}
    	else {
    		?>
    		<h1 class="entry-title"><?php _e( 'No Posts Found.', 'attitude' ); ?></h1>
          <?php
       }
    }
    endif;
    ?>

    Thank you

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.