插件的中等大小图像称为动态特色图像

时间:2014-07-19 18:07:49

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

我正在使用动态特色图片并将多个产品图片添加到单个自定义帖子类型名称作为单个产品的产品但是我正在尝试在我的模板中获取这些图像但是该数组仅返回我两个尺寸[thumb ] [完整]但我需要中等以下是我的代码

<?php 

  if( class_exists('Dynamic_Featured_Image') ) {
  global $dynamic_featured_image;

  $featured_images = $dynamic_featured_image->get_featured_images();

  foreach($featured_images as $featured_image) {

?>
    <a href="<?php echo $featured_image['full'];?>" rel="rings" rev="<?php echo $featured_image['medium'];?>"><img width="60" src="<?php echo $featured_image['full'];?>"/></a>
<?php }

  }
?>

正如你们可以在锚标签中看到的那样$ feature_image [&#39; medium&#39;]这就是我想要回应这个锚标签的方式,但遗憾的是它并没有让我恢复中等大小而且我需要帮助获得中等大小。下面是我得到的数组,你可以清楚地看到[拇指]和[完整]。请帮忙

 Array
(
  [thumb] => http://www.example.com/wp-content/uploads/2014/07/product-1-120x90.jpg
  [full] => http://www.example.com/wp-content/uploads/2014/07/product-1.jpg
  [attachment_id] => 254
)

1 个答案:

答案 0 :(得分:2)

您需要通过调用get_image_url函数来获取中等大小的图像。试试这个:

<?php     
    if( class_exists('Dynamic_Featured_Image') ) {
    global $dynamic_featured_image;

    $featured_images = $dynamic_featured_image->get_featured_images();

    foreach($featured_images as $featured_image) {
            $mediumSizedImage = $dynamic_featured_image->get_image_url($featured_image['attachment_id'], 'medium');       
               echo "<img src = '" . $mediumSizedImage . "' />";
        ?>
        <a href="<?php echo $featured_image['full'];?>" rel="rings" rev="<?php echo $mediumSizedImage ?>"><img width="60" src="<?php echo $featured_image['full'];?>"/></a>
    <?php }

    }
?>

所有可用功能都记录在案here

PS:我是plugin的作者。