Medium size image by plugin called dynamic featured image

穿精又带淫゛_ 提交于 2019-12-01 09:51:32

问题


i am using dynamic featured image and adding multiple product images to a single custom post type name as products for a single product but and i am trying to get those images in my template but the array only return me only two sizes [thumb] [full] but i need medium as well below is my code

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

  }
?>

As you guys can see in the anchor tag $featured_image['medium'] this is how i want to echo this anchor tag but unfortunately it don't return me the medium size and i need help in getting the medium size as well. below is the array that i get where you can clearly see only [thumb] and [full]. please help

 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:


You need to get medium sized image by calling get_image_url function. Try this:

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

    }
?>

All available functions are documented here.

PS: I am author of the plugin.



来源:https://stackoverflow.com/questions/24843444/medium-size-image-by-plugin-called-dynamic-featured-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!