Exemple #1
0
 /**
  * Vytvoří set pro html tag picture
  * 
  * @author Jan Pokorný
  * @param WP_Post $post Attachment
  * @param string $defaultSize Wordpress velikost obrázku pro <img>
  * @param int $width Šířka - nutné pro lazyload
  * @param int $height Výška - nutné pro lazyload
  * @param array min-width => wordpress velikost - 1024 => KT_IMG_SIZE_SLIDER
  * @param array $imgAttrs Attributy pro img tag atribute => hodnota
  * @return string Kolekce tagů <img> x * <source>
  */
 public static function imageGetPictureSet(WP_Post $post, $defaultSize, $width, $height, $sizes = [], $imgAttrs = [])
 {
     $picture = "";
     foreach ($sizes as $minWidth => $size) {
         $picture .= sprintf('<source srcset="%s" media="(min-width:%spx)">', wp_get_attachment_image_url($post->ID, $size), $minWidth);
     }
     $imgAttrs = array_merge(["alt" => $post->post_title], $imgAttrs);
     $picture .= KT::imageGetHtmlByUrl(wp_get_attachment_image_url($post->ID, $defaultSize), $width, $height, $imgAttrs);
     return $picture;
 }