• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

PHP help: showing featured image on pages

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

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

This topic is: not resolved

Tagged: featured image, pages, php, thumbnail

  • This topic has 1 reply, 1 voice, and was last updated 10 years, 1 month ago by balletuni.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • February 6, 2013 at 1:16 pm #18477
    balletuni
    Member

    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

    February 6, 2013 at 1:26 pm #18479
    balletuni
    Member

    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.

  • Author
    Posts
Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘Design Tips and Tricks’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2023 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble