Displaying Featured Image on a Page

I finally found the magic words to display a featured image where I want it on a page. I’ve been using the Genesis WordPress framework and struggling to figure this out. Thanks to several different forum responses and especially Nick the Greek’s tutorials I finally have an answer.

Here’s the deal. I wanted to have a full width image that displays between the header and the content.

Using the Genesis Simple Hooks plugin to simplify putting the code in, I put the following code into the genesis_before_content_sidebar_wrap Hook
<?php
genesis_image(
array(
'format' => 'html',
'size' => 'full',
'num' => 0,
'attr' => array( 'class' => 'feature' )
)
);
?>

An important element was setting the size to ‘full’ and the “num” to “0″. Having ‘num’ set to 0 says to pull the featured image. If there is no featured image, it will pull the first image from the post/page. So you have to have a featured image or you may get unwanted results.

The ‘class’ element can be anything, that just outputs a class on the image tag.

Now  I can upload a featured image on a page and it will display automatically above the content!

A little more fun – show something different on the home page

To take this a bit further, I needed to display a slideshow on the home page rather than the featured image. Ended up doing it like this:

<?php
if (is_front_page()) {
echo do_shortcode('[ slideshow id=1 ]');
} else {
genesis_image(
array(
'format' => 'html',
'size' => 'full',
'num' => 0,
'attr' => array( 'class' => 'feature' )
)
);
}
?>