PHP help for displaying featured images on pages
-
I want to show featured image thumbnails on pages (to appear before the page title and content), but only if there is a featured image defined for that page (otherwise, I don’t want any image to appear above the page title).
With the code below, I get the desired result. However, it kills the featured image thumbnails on my archive pages and on my posts…
add_action( 'genesis_before_post_title', 'genesis_post_info' ); add_action('genesis_post_title','generate_post_image', 5); function generate_post_image() { if ( is_page() || ! genesis_get_option( 'content_archive_thumbnail' ) ) return; if ( is_page() && has_post_thumbnail() ) { printf( $image ); } else { return; } if ( $image = genesis_get_image( array( 'format' => 'url', 'size' => genesis_get_option( 'image_size' ) ) ) ) { printf( '<a href="%s" rel="bookmark"><img class="post-image" src="%s" alt="%s" /></a>', get_permalink(), $image, the_title_attribute( 'echo=0' ) ); }
If I remove this portion…
if ( is_page() && has_post_thumbnail() ) { printf( $image ); } else { return; }
…then my archives and posts look perfect, but I am back to where I started with no featured images on the pages.
I am using the Genesis framework from Studiopress.
What am I doing wrong? My website is: http://www.balletuni.com
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘PHP help for displaying featured images on pages’ is closed to new replies.