我安装了最新的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中,然后在阵列中显示。
我是否遗漏了我需要做的其他事情?
答案 0 :(得分:0)
您在代码中打印的内容是插件动态特色图片3.1.2添加的自定义特色图片(特色图片2以后):
<?php if( class_exists('Dynamic_Featured_Image') ) {...
..而编辑帖子屏幕中的第一个“特色图片”在wordpress核心本身中实现,可以使用the_post_thumbnail
函数打印(请参阅http://codex.wordpress.org/Function_Reference/the_post_thumbnail)。
答案 1 :(得分:0)
您可以使用此功能获取所有精选图像,包括默认的WordPress图像:
/**
* 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的master branch中的文件。
P.S。我是plugin的作者。