PHP help: showing featured image on pages

Community Forums Forums Design Tips and Tricks PHP help: showing featured image on pages

This topic is: not resolved

This topic contains 1 reply, has 1 voice, and was last updated by  balletuni 1 year, 2 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #18477

    balletuni
    Participant
    Post count: 1

    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.

    What am I doing wrong? My website is: http://www.balletuni.com

    #18479

    balletuni
    Participant
    Post count: 1

    Actually, this portion from the above code kills the desired result of featured images on pages:

    if ( is_page() || ! genesis_get_option( ‘content_archive_thumbnail’ ) )
    return;

    So this is the code that gets the desired result:

    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() && 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′ ) );
    }

    }

    …except that it kills the thumbnails on archives and posts.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.