-1

I am having some issues trying to get featured image to appear on my front page.

I am using Genesis, then genesis child theme. I only want the featured image to appear on my front-page.php. I know I need to write a custom loop in order for the featured image to appear only. However I am having trouble completing it.I am not sure what code to write into my custom loop.

I did this:

/** Code for custom loop */
function my_custom_loop() {

}

/** Replace the standard loop with our custom loop */
remove_action( 'genesis_loop', 'genesis_do_loop' );
add_action( 'genesis_loop', 'my_custom_loop' );
1
  • This should be posted on the StudioPress Forums Nov 20, 2014 at 20:44

2 Answers 2

0

Like @jdm2112, I'm not a Gensis user, but here is an alternative method to retrieving the featured image. I use this method because it offers more functionality to altering the featured image (ie: thumbnail size).

You can add these functions to your functions.php file.

public function get_featured_image_id() {
    return (int) $this->get_meta( '_thumbnail_id' );
}

/**
 * Get the featured image url for the given featured image id
 *
 * @param string $size
 * @return string|false
 */
public function get_featured_image_url( $size = 'full' ) {

    $attachment_id = $this->get_featured_image_id();
    if ( ! $attachment_id ) {
        return false;
    }
    $src = wp_get_attachment_image_src( $attachment_id, $size );
    if ( ! $src ) {
        return false;
    }

    return $src[0];
}

/**
 * Get the HTML for the featured image html
 *
 * @return string
 */
public function get_featured_image_html( $size = 'full' ) {

    if ( $featured_image_id = $this->get_featured_image_id() ) {
        return wp_get_attachment_image( $featured_image_id, $size, '' );
    } else {
        return '';
    }
}

Use case in your WordPress "The Loop"

echo esc_url( $post->get_featured_image_url( the_id() ) );
2
  • stoopkid1 and jdm2112, I will try this once I get home.Thanks.
    – David
    Jul 14, 2014 at 2:00
  • -1 Answering off topic questions Nov 20, 2014 at 20:45
0

Displaying the featured image (referred to as 'thumbnail' in Wordpress functions) should not require you to replace your page loop. I'm not a Genesis user so there's a chance that is the case.

Displaying a feature image for the page is as simple as using the the_post_thumbnail function. Here is the Codex Function Reference for full details.

Simply use this where you want an image to be displayed in your page template:

<?php the_post_thumbnail(); ?>
1
  • -1 Answering off topic questions Nov 20, 2014 at 20:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.