【问题标题】:multiple featured image wordpress多个特色图片 wordpress
【发布时间】:2014-05-13 07:21:45
【问题描述】:

我想制作一个带有徽标和商家照片的商家页面。 我为此使用了自定义帖子类型。但是,我无法使第二张特色图片正常工作。 我想让它在没有插件的情况下工作。 这是我的代码:

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'
   ) );
 }

【问题讨论】:

    标签: wordpress image featured


    【解决方案1】:

    嗯,

    一些插件可用于多个特色图像,即Dynamic Featured ImageMultiple Featured Images。 您可以通过这些插件轻松管理它们。

    【讨论】:

    • 我想使用尽可能少的插件。但如果我不能让它工作,我会使用其中一个插件。谢谢
    【解决方案2】:

    你可以通过这个插件简单地做到这一点: dynamic featured image

    你可以通过这种方式在前端获取这些多张图片:

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

    【讨论】:

    • 你先生是个传奇!
    猜你喜欢
    • 1970-01-01
    • 2012-01-16
    • 2019-07-31
    • 2015-04-28
    • 2015-07-17
    • 2014-11-22
    • 2015-04-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多