Medium size image by plugin called dynamic feature

2019-02-20 05:49发布

问题:

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.