我实际上在一个带有Dessign.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 .
希望这是可以理解的 .
1 回答
我最近不得不自己寻找类似的答案 . 插件作者非常擅长解释如何实际设置插件,但并没有真正说明如何获取图像,而是将其留给开发人员 . 所以,我觉得你 .
如果我理解正确,您需要从插件中获取精选图像,而不是WordPress中包含的精选图像 .
在此插件中,您可以为每个帖子/页面创建无限量的精选图像 . 上面的代码仅用于抓取第一个图像 created by the plugin . 这是调用图像本身的
$featured_image['full']
.您还可以将显示的图像类型更改为其他尺寸,包括您创建的任何自定义尺寸 . 使用这些尺寸的代码可以在this post.找到