动态特色图片-WordPress-未获取第一张特色图片

动态特色图片-WordPress-未获取第一张特色图片,wordpress,dynamic-featured-image,Wordpress,Dynamic Featured Image,我已经安装了最新的Dynamic Featured Image 3.1.2,当我尝试在页面上打印功能图像阵列时,我只会得到功能图像2及更高版本 <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <?php if( class_exists('Dynamic_Featured_Image') ) { global $dynamic_featured_image;

我已经安装了最新的Dynamic Featured Image 3.1.2,当我尝试在页面上打印功能图像阵列时,我只会得到功能图像2及更高版本

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

    <?php 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
    } ?>

    ... << rest of Post Loop >>

... >
尽管我添加了多个特色图像,但它仅显示阵列中的特色图像2和其他图像


我是否错过了我需要做的其他事情?

您在代码中打印的是由插件Dynamic Featured Image 3.1.2添加的自定义特征图像(特征图像2之后):

<?php if( class_exists('Dynamic_Featured_Image') ) {...

使用此功能,您可以获得包括默认WordPress one在内的所有特色图像:

/**
 * Retrieve featured images for specific post(s) 
 * including the default Featured Image
 *
 * @since 3.1.2
 * @access public
 *
 * @see  $this->get_featured_images()
 *
 * @param Integer $post_id id of the current post
 *
 * @return Array An array of images or an empty array on failure
 */
public function get_all_featured_images( $post_id = null ) {

    if ( is_null( $post_id ) ) {
        global $post;
        $post_id = $post->ID;
    }

    $thumbnail_id = get_post_thumbnail_id( $post_id );

    $featured_image_array = array();
    if ( ! empty( $thumbnail_id ) ) {
        $featured_image = array(
            'thumb' => wp_get_attachment_thumb_url( $thumbnail_id ),
            'full' => wp_get_attachment_url( $thumbnail_id ),
            'attachment_id' => $thumbnail_id
        );
        $featured_image_array[] = $featured_image;
    }

    $dfiImages = $this->get_featured_images( $post_id );

    $all_featured_images = array_merge( $featured_image_array, $dfiImages );

    return $all_featured_images;

}
此功能将包含在下一版本的插件中。在此之前,您可以将其添加到
dynamic featured image.php
插件文件中,也可以从github下载并使用该文件


另外,我是的作者。

此函数存在缓存问题或其他问题。我用的是
full
,而不是用裁剪过的图像。找不到这样做的方法,所以我被切换到
thumb
。wordpress中的默认拇指为150x150。更改为400x300并重新生成了缩略图,链接仍为150x150。也移除了旧的150x150,进行了另一次重新生成,现在我断开了链接。。