WP动态特色图片 - 无法获得第二个特色图片网址

时间:2022-06-18 06:07:02

I'm actually working on a wordpress website with a Dessign.net theme (the pixel one) which got a beautiful full-page slider on the front page. The slider shows the featured image of selected posts (post for which i've checked "show in slideshow" in the meta box field on edit page).

我实际上在一个带有Dessign.net主题(像素一)的wordpress网站上工作,它在首页上有一个漂亮的整页滑块。滑块显示所选帖子的精选图像(我在编辑页面的元框字段中检查了“以幻灯片形式显示”的帖子)。

Those featured image are used in the same way for different view on the site (eg. thumbnails). I need them for the thumbnails, but i'ld like another image (still relative to selected posts) for the home-page slider.

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

I've found that "Dynamic Featured Image" plugins for wordpress but now i can't achieve to get the second featured image url in the slider's loop.

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

Here's the part of code for the slider, as it was with the theme:

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

<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>

Now i've tried to put the code found on the plugin github page:

现在我已经尝试将代码放在插件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

              }

in place of $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()),'full');

But $thumb return array as a string

但是$ thumb返回数组作为字符串

I tried a few different things but i'm not fluent in php.

我尝试了一些不同的东西,但我不会流利的PHP。

Hope this is understandable.

希望这是可以理解的。

1 个解决方案

#1


I had to recently look for answers on something like this myself. The plugin author is great at explaining how to actually set up the plugin, but doesn't really say how to get the images, leaving it up to the developer. So, I feel you.

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

If I understand you correctly, you need to get the featured image from the plugin, not the featured image included in WordPress.

如果我理解正确,您需要从插件中获取精选图像,而不是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>";

} ?>

In this plugin, you can create infinite amounts of featured images per post/page. This code above is only for grabbing the first image created by the plugin. It's $featured_image['full'] that calls the image itself.

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

You can change the type of image shown to other sizes as well, including any custom sizes you create. The code to use those sizes can be found on this post.

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

#1


I had to recently look for answers on something like this myself. The plugin author is great at explaining how to actually set up the plugin, but doesn't really say how to get the images, leaving it up to the developer. So, I feel you.

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

If I understand you correctly, you need to get the featured image from the plugin, not the featured image included in WordPress.

如果我理解正确,您需要从插件中获取精选图像,而不是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>";

} ?>

In this plugin, you can create infinite amounts of featured images per post/page. This code above is only for grabbing the first image created by the plugin. It's $featured_image['full'] that calls the image itself.

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

You can change the type of image shown to other sizes as well, including any custom sizes you create. The code to use those sizes can be found on this post.

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