动态特色图片

时间:2013-11-16 16:36:38

标签: php arrays wordpress wordpress-plugin dynamic-featured-image

我最近为wordpress安装了Dynamic Featured Image插件。但我不知道如何链接图像。我正在尝试创建一个像这样的画廊http://www.subcreative.com.au/#work - 向下滚动到项目,你会看到。

我已将此代码放在functions.php

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

   if( function_exists('dfi_get_featured_images') ) {
       $featuredImages = dfi_get_featured_images();

       //Now, loop through the image to display
   }

   endwhile;
?>

并用它来链接图像。

echo ' <a class="fancybox" href="'. dfi_get_featured_images() .'" style="text-align:center">Take a look</a> '; ?>

但是当我尝试打开图像时,它变为“/ array”

3 个答案:

答案 0 :(得分:3)

我不是wordpress dev,但我在wordpress网站上看到过这个我试图解决的问题。 所以也许你可以试试这个。

if( class_exists('Dynamic_Featured_Image') ):
    global $dynamic_featured_image;
    global $post;
     $featured_images = $dynamic_featured_image->get_featured_images( $post->ID );

     if ( $featured_images ):
        ?>
            <?php foreach( $featured_images as $images ): ?>
               <img src="<?php echo $images['full'] ?>" alt="">
            <?php endforeach; ?>
        <?php
        endif;
endif;

这适用于我的情况。我正在使用DFI 3.1.13

答案 1 :(得分:2)

  

此答案仅适用于插件版本2.0.2及更低版本。

您需要遍历返回的数组并手动显示图像。试试这个:

<?php   

    if( function_exists('dfi_get_featured_images') ) {
       $featuredImages = dfi_get_featured_images();

       //Loop through the image to display your image

       if( !is_null($featuredImages) ){

            $links = array();

            foreach($featuredImages as $images){
                $thumb = $images['thumb'];
                $fullImage = $images['full'];

                $links[] = "<a href='{$fullImage}' class='dfiImageLink'><img src='{$thumb}' /></a>";
            }

            echo "<div class='dfiImages'>";
            foreach($links as $link){
              echo $link;
            }                
            echo "</div>";
         }        
    }

?>

答案 2 :(得分:0)

试试这里有帖子循环

$img=dfi_get_featured_images();
$url=$img['full'];
echo ' <a class="fancybox" href="'. $full .'" style="text-align:center">Take a look</a> ';

如果完全无效,请尝试拇指。