3

我实际上正在开发一个带有 Design.net 主题(像素主题)的 wordpress 网站,该网站在首页上有一个漂亮的整页滑块。滑块显示所选帖子的特色图片(我已在编辑页面的元框字段中选中“在幻灯片中显示”的帖子)。

这些特色图像以相同的方式用于网站上的不同视图(例如缩略图)。我需要它们作为缩略图,但我希望主页滑块的另一个图像(仍然相对于选定的帖子)。

我发现了 wordpress 的“动态特色图片”插件,但现在我无法在滑块循环中获取第二个特色图片网址。

这是滑块的代码部分,与主题一样:

<ul>
        <?php
        $slider_arr = array();
        $x = 0;
        $args = array(
             //'category_name' => 'blog',
             'post_type' => 'post',
             'meta_key' => 'ex_show_in_slideshow',
             'meta_value' => 'Yes',
             'posts_per_page' => 99
             );
        query_posts($args);
        while (have_posts()) : the_post();



             $thumb = wp_get_attachment_image_src( get_post_thumbnail_id(get_the_ID()), 'full' );
            //$thumb = wp_get_attachment_image_src( get_post_thumbnail_id(get_the_ID()), 'large' );
            $img_url = $thumb['0'];
        ?>
            <li data-background="<?php echo $img_url; ?>" onclick="location.href='<?php the_permalink(); ?>';" style="cursor:pointer;">

            </li>
        <?php array_push($slider_arr,get_the_ID()); ?>
        <?php $x++; ?>
        <?php endwhile; ?>
        <?php wp_reset_query(); ?>

    </ul>

现在我尝试将在插件 github 页面上找到的代码:

if( class_exists('Dynamic_Featured_Image') ) {
               global $dynamic_featured_image;
              $thumb = $dynamic_featured_image->get_featured_images( );

                        //You can now loop through the image to display them as required

              }

代替$thumb = wp_get_attachment_image_src( get_post_thumbnail_id(get_the_ID()), 'full' );

但作为字符串$thumb返回array

我尝试了一些不同的东西,但我不精通 php。

希望这是可以理解的。

4

1 回答 1

4

我最近不得不自己寻找类似这样的答案。插件作者非常擅长解释如何实际设置插件,但并没有真正说明如何获取图像,而是由开发人员决定。所以,我感觉到你了。

如果我理解正确,您需要从插件中获取特色图片,而不是 WordPress 中包含的特色图片。

<?php global $dynamic_featured_image;
$featured_images = $dynamic_featured_image->get_featured_images( get_the_ID() );

//You can now loop through the image to display them as required
foreach($featured_images as $featured_image) {

echo "<a href='".get_the_permalink()."' class='slide'>";
echo "<span> <img src='".$featured_image['full']."' /> </span>";
echo "</a>";

} ?>

在这个插件中,您可以为每个帖子/页面创建无限数量的特色图片。上面的代码仅用于抓取插件创建的第一张图像。它$featured_image['full']调用了图像本身。

您也可以将显示的图像类型更改为其他尺寸,包括您创建的任何自定义尺寸。可以在这篇文章中找到使用这些尺寸的代码。

于 2015-07-03T01:34:12.270 回答