multiple featured image wordpress

andre de waard picture andre de waard · Apr 2, 2014 · Viewed 10.7k times · Source

I want to make a business page that has a logo and a photo of the business itself. I use a custom post-type for this. However i can not make the second featured image to work. I want to make it work without a plugin. this is my code:

function create_post_type() {
    register_post_type( 
        'Bedrijven', array(
            'labels' => array(
            'name' => __( 'Bedrijven' ),
            'singular_name' => __( 'bedrijf' )
            ),
        'public' => true,
        'has_archive' => true,
        'supports' => array(
            'title',
            'editor',
            'comments',
            'excerpt',
            'thumbnail',
            'author',
            'MultiPostThumbnails',
            'page-attributes',)

        )
    );
}
add_action( 'init', 'create_post_type' );


if (class_exists('MultiPostThumbnails')) {
  new MultiPostThumbnails(array(
     'label' => 'Thumbnail Image',
     'id' => 'thumbnail-image',
     'post_type' => 'bedrijven'
   ) );
 }

Answer

Dinesh picture Dinesh · Apr 2, 2014

You can do it simply by this plugin: dynamic featured image

and you can get these multiple image on front end by this way:

 if( class_exists('Dynamic_Featured_Image') ) {
    global $dynamic_featured_image;

    $featured_images = $dynamic_featured_image->get_featured_images( );
    //print_r($featured_images);

    //You can now loop through the image to display them as required
    foreach($featured_images as $featured_image) {
        echo "<img src='".$featured_image['full']."'></a>";
    }

 }