多个特色图像wordpress

and*_*ard 1 wordpress image featured

我想创建一个商业页面,其中包含商标本身的徽标和照片.我为此使用自定义post-type.但是,我无法使第二个特色图像工作.我想让它在没有插件的情况下工作.这是我的代码:

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'
   ) );
 }
Run Code Online (Sandbox Code Playgroud)

Din*_*esh 6

你可以通过这个插件简单地完成它: 动态特色图像

你可以通过这种方式在前端获得这些多个图像:

 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>";
    }

 }
Run Code Online (Sandbox Code Playgroud)