2

我最近为 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”

4

3 回答 3

4

我不是 wordpress 开发人员,但我在我试图修复的 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

于 2014-10-08T00:52:59.487 回答
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>";
         }        
    }

?>
于 2013-11-16T17:23:52.743 回答
0

在有帖子循环中试试这个

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

如果完整不起作用,请尝试拇指。

于 2013-11-16T17:22:49.653 回答