Community Forums › Forums › Archived Forums › General Discussion › how to show featured image in post
Tagged: featured image, post
- This topic has 10 replies, 2 voices, and was last updated 9 years, 8 months ago by gswartz.
-
AuthorPosts
-
August 27, 2014 at 9:09 am #121335gswartzMember
I am using the genesis sample theme and even though a featured image is set on a post, it's not showing in the post when I view it. I've googled quite a bit but can't seem to find a solution. So, how do you do this and why isn't this supported out of the box?
I do have "Include the Featured Image" turned on under Genesis>Theme Settings>Content Archives and the featured image shows on the blog page... just not the individual post.
Thanks.
http://uhpartners.hiringhook.com/blog/August 27, 2014 at 9:18 am #121337Brad DaltonParticipantIts supported in Genesis as you can see in genesis > lib > functions > image.php line 99
//* Else if first-attached, pull the first (default) image attachment elseif ( 'first-attached' === $args['fallback'] ) { $id = genesis_get_image_id( $args['num'], $args['post_id'] ); $html = wp_get_attachment_image( $id, $args['size'], false, $args['attr'] ); list( $url ) = wp_get_attachment_image_src( $id, $args['size'], false, $args['attr'] );
Are you referring to single posts or archives?
August 27, 2014 at 9:25 am #121338gswartzMemberSingle posts. For example, if you go to the link I provided in the original post you'll see the featured image shows up in the blog index page. But not on the single page - http://uhpartners.hiringhook.com/2014/08/25/the-first-round-draft-pick/
August 27, 2014 at 10:46 am #121358Brad DaltonParticipantYou can add your single posts featured images before or after your titles using this code
August 27, 2014 at 10:57 am #121361gswartzMemberAwesome, thank you very much!
August 29, 2014 at 8:36 am #121687gswartzMemberApparently I'm missing something. I used this code from the link you provided and it did show the featured image.
add_action( 'genesis_entry_header', 'single_post_featured_image', 15 );
function single_post_featured_image() {
if ( ! is_singular( 'post' ) )
return;
$img = genesis_get_image( array( 'format' => 'html', 'size' => genesis_get_option( 'image_size' ), 'attr' => array( 'class' => 'post-image' ) ) );
printf( '%s', get_permalink(), the_title_attribute( 'echo=0' ), $img );
}I didn't think to remove the featured image but just tried that and now the image still shows, even after being removed from the post. What do I need to change to make it only show the featured image when the featured image is set?
August 29, 2014 at 8:48 am #121694gswartzMemberI tweaked the code a bit to this which works on the single page.
add_action( 'genesis_entry_header', 'single_post_featured_image', 15 );
function single_post_featured_image() {
if (! is_singular( 'post' ) )
return;
if ( !has_post_thumbnail() ) return;$img = genesis_get_image( array( 'format' => 'html', 'size' => genesis_get_option( 'image_size' ), 'attr' => array( 'class' => 'post-image' ) ) );
printf( '%s', get_permalink(), the_title_attribute( 'echo=0' ), $img );
}The problem I have now is that I previously had "include featured image?" turned on in the genesis theme settings which made it show up on the blog index page. But, again when the featured image is removed, with this setting turned on, it still shows the old featured image. If I disable this option, then no featured image shows up. So, for the blog index page, how can I get the featured image to show up only if it's actually set?
August 29, 2014 at 9:13 am #121697Brad DaltonParticipantThat code is broken and cannot be tested because it hasn't been embedded properly.
Please link to the code or embed it using Github Gists
August 29, 2014 at 9:17 am #121700gswartzMemberSorry about that. Is this what you meant?
add_action( ‘genesis_entry_header’, ‘single_post_featured_image’, 15 ); function single_post_featured_image() { if (! is_singular( ‘post’ ) ) return; if ( !has_post_thumbnail() ) return; $img = genesis_get_image( array( ‘format’ => ‘html’, ‘size’ => genesis_get_option( ‘image_size’ ), ‘attr’ => array( ‘class’ => ‘post-image’ ) ) ); printf( ‘%s‘, get_permalink(), the_title_attribute( ‘echo=0′ ), $img ); }
August 29, 2014 at 9:30 am #121701Brad DaltonParticipantSorry buts that not my code, i mean its modified. Not sure what your problem is as the code on my site has been used hundreds of times and never been a problem with others.
Maybe someone else might like to review your code or maybe its a problem with other code in your files.
August 29, 2014 at 9:46 am #121705gswartzMemberSorry, somehow I got some code mixed up. Here is what I'm using...
add_action( 'genesis_entry_header', 'single_post_featured_image', 15 ); function single_post_featured_image() { if (! is_singular( 'post' ) ) return; if ( !has_post_thumbnail() ) return; $img = genesis_get_image( array( 'format' => 'html', 'size' => genesis_get_option( 'image_size' ), 'attr' => array( 'class' => 'post-image' ) ) ); printf( '<a href="%s" title="%s" class="blog-featured-image">%s</a>', get_permalink(), the_title_attribute( 'echo=0' ), $img ); }
I believe this matches the 'DISPLAY FEATURED IMAGE AFTER TITLE' code from the link you provided with the only differences being the class I added to the link and also the has_post_thumbnail() return check.
However, I don't think this is causing the issue because this code would be specific to the blog single page, not the index page, right?
So, really my main issue now is only with the blog index page - trying to figure out how to get the featured image to show up in the list of blog entries. Again, if I enable the 'include featured image' setting under genesis theme settings it does show up, but it continues to show up even if I remove the featured image from the post.
-
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.