Example #1
0
 public function get_html($media_id, $sizes = null, array $attrs = array(), $square = false, $def_wp_size = null, $use_fallback = false)
 {
     if (empty($def_wp_size)) {
         $def_wp_size = $square ? 'thumbnail' : 'medium';
     }
     $img_src = wp_get_attachment_image_url($media_id, $def_wp_size);
     if (empty($img_src)) {
         $result = $use_fallback ? call_user_func_array(array($this, 'get_html_fallback'), func_get_args()) : false;
         return $result;
     }
     $img_srcset = wp_get_attachment_image_srcset($media_id, $def_wp_size);
     $img_data = array();
     foreach (get_intermediate_image_sizes() as $size) {
         $img_data[$size] = wp_get_attachment_image_src($media_id, $size);
     }
     $img_data = $this->filter_square($img_data, $square);
     if (!empty($this->filter_srcset)) {
         foreach ($this->filter_srcset as $filter) {
             $img_srcset = call_user_func($filter, $img_data, $media_id, $size, $attrs, $square, $def_wp_size);
         }
     }
     $attrs = array_merge(array('src' => $img_src, 'srcset' => $img_srcset, 'sizes' => $this->get_sizes($sizes)), $attrs);
     if (empty($attrs['srcset'])) {
         unset($attrs['srcset']);
         unset($attrs['sizes']);
     }
     $result = \Cibulka::Base('HTML', 'img', $attrs, true);
     return $result;
 }
Example #2
0
 function get_thumbnail_source($post_id = null)
 {
     $id = get_post_thumbnail_id($post_id);
     $src = wp_get_attachment_image_srcset($id, 'medium', true);
     if (!$src) {
         $src = wp_get_attachment_url($id);
         $src = $src;
     }
     return $src;
 }
Example #3
0
 /**
  * Get uploaded file information
  *
  * @param int   $file Attachment image ID (post ID). Required.
  * @param array $args Array of arguments (for size).
  *
  * @return array|bool False if file not found. Array of image info on success
  */
 public static function file_info($file, $args = array())
 {
     if (!($path = get_attached_file($file))) {
         return false;
     }
     $args = wp_parse_args($args, array('size' => 'thumbnail'));
     list($src) = wp_get_attachment_image_src($file, $args['size']);
     $attachment = get_post($file);
     $info = array('ID' => $file, 'name' => basename($path), 'path' => $path, 'url' => $src, 'full_url' => wp_get_attachment_url($file), 'title' => $attachment->post_title, 'caption' => $attachment->post_excerpt, 'description' => $attachment->post_content, 'alt' => get_post_meta($file, '_wp_attachment_image_alt', true));
     if (function_exists('wp_get_attachment_image_srcset')) {
         $info['srcset'] = wp_get_attachment_image_srcset($file);
     }
     return wp_parse_args($info, wp_get_attachment_metadata($file));
 }
/**
 * Filter to add 'srcset' and 'sizes' attributes to post thumbnails and gallery images.
 * The filter is added to the hook in wp-tevko-core-functions.php because
 * it is only needed on a version of WordPress previous to 4.4.
 *
 * @since 2.3.0
 * @see 'wp_get_attachment_image_attributes'
 *
 * @return array Attributes for image.
 */
function tevkori_filter_attachment_image_attributes($attr, $attachment, $size)
{
    // Set 'srcset' and 'sizes' if not already present and both were returned.
    if (empty($attr['srcset'])) {
        $srcset = wp_get_attachment_image_srcset($attachment->ID, $size);
        $sizes = wp_get_attachment_image_sizes($attachment->ID, $size);
        if ($srcset && $sizes) {
            $attr['srcset'] = $srcset;
            if (empty($attr['sizes'])) {
                $attr['sizes'] = $sizes;
            }
        }
    }
    return $attr;
}
Example #5
0
 /**
  * Get uploaded file information
  *
  * @param int   $file Attachment image ID (post ID). Required.
  * @param array $args Array of arguments (for size).
  *
  * @return array|bool False if file not found. Array of image info on success
  */
 public static function file_info($file, $args = array())
 {
     if (!($path = get_attached_file($file))) {
         return false;
     }
     $args = wp_parse_args($args, array('size' => 'thumbnail'));
     $image = wp_get_attachment_image_src($file, $args['size']);
     $attachment = get_post($file);
     $info = array('ID' => $file, 'name' => basename($path), 'path' => $path, 'url' => $image[0], 'full_url' => wp_get_attachment_url($file), 'title' => $attachment->post_title, 'caption' => $attachment->post_excerpt, 'description' => $attachment->post_content, 'alt' => get_post_meta($file, '_wp_attachment_image_alt', true));
     if (function_exists('wp_get_attachment_image_srcset')) {
         $info['srcset'] = wp_get_attachment_image_srcset($file);
     }
     $info = wp_parse_args($info, wp_get_attachment_metadata($file));
     // Do not overwrite width and height by returned value of image meta
     $info['width'] = $image[1];
     $info['height'] = $image[2];
     return $info;
 }
Example #6
0
/**
 *
 */
function gannet_responsive_thumbnail($attachment_id)
{
    $src = wp_get_attachment_image_url($attachment_id, 'medium');
    $srcset = wp_get_attachment_image_srcset($attachment_id, 'medium');
    $alt = get_post_meta($attachment_id, '_wp_attachment_image_alt', true);
    ?>
	<img src="<?php 
    echo esc_url($src);
    ?>
"
		class="post-thumbnail"
		alt="<?php 
    echo esc_textarea($alt);
    ?>
"
		srcset="<?php 
    echo esc_attr($srcset);
    ?>
"
		sizes="768px, (min-width: 768px) 300px">
  <?php 
}
    function test_wp_make_content_images_responsive_schemes()
    {
        $image_meta = wp_get_attachment_metadata(self::$large_id);
        $size_array = array((int) $image_meta['sizes']['medium']['width'], (int) $image_meta['sizes']['medium']['height']);
        $srcset = sprintf('srcset="%s"', wp_get_attachment_image_srcset(self::$large_id, $size_array, $image_meta));
        $sizes = sprintf('sizes="%s"', wp_get_attachment_image_sizes(self::$large_id, $size_array, $image_meta));
        // Build HTML for the editor.
        $img = get_image_tag(self::$large_id, '', '', '', 'medium');
        $img_https = str_replace('http://', 'https://', $img);
        $img_relative = str_replace('http://', '//', $img);
        // Manually add srcset and sizes to the markup from get_image_tag();
        $respimg = preg_replace('|<img ([^>]+) />|', '<img $1 ' . $srcset . ' ' . $sizes . ' />', $img);
        $respimg_https = preg_replace('|<img ([^>]+) />|', '<img $1 ' . $srcset . ' ' . $sizes . ' />', $img_https);
        $respimg_relative = preg_replace('|<img ([^>]+) />|', '<img $1 ' . $srcset . ' ' . $sizes . ' />', $img_relative);
        $content = '
			<p>Image, http: protocol. Should have srcset and sizes.</p>
			%1$s

			<p>Image, http: protocol. Should have srcset and sizes.</p>
			%2$s

			<p>Image, protocol-relative. Should have srcset and sizes.</p>
			%3$s';
        $unfiltered = sprintf($content, $img, $img_https, $img_relative);
        $expected = sprintf($content, $respimg, $respimg_https, $respimg_relative);
        $actual = wp_make_content_images_responsive($unfiltered);
        $this->assertSame($expected, $actual);
    }
}
?>

<?php 
$src = siteorigin_widgets_get_attachment_image_src($image, $size, $image_fallback);
$attr = array();
if (!empty($src)) {
    $attr = array('src' => $src[0]);
    if (!empty($src[1])) {
        $attr['width'] = $src[1];
    }
    if (!empty($src[2])) {
        $attr['height'] = $src[2];
    }
    if (function_exists('wp_get_attachment_image_srcset')) {
        $attr['srcset'] = wp_get_attachment_image_srcset($image, $size);
    }
}
$attr = apply_filters('siteorigin_widgets_image_attr', $attr, $instance, $this);
$classes = array('so-widget-image');
if (!empty($title)) {
    $attr['title'] = $title;
}
if (!empty($alt)) {
    $attr['alt'] = $alt;
}
?>
<div class="sow-image-container">
<?php 
if (!empty($url)) {
    ?>
/**
 * Gets data about an attachment, such as alt text and captions.
 * @since 2.6.0
 * @param object|bool $product
 * @return array
 */
function wc_get_product_attachment_props($attachment_id = null, $product = false)
{
    $props = array('title' => '', 'caption' => '', 'url' => '', 'alt' => '', 'src' => '', 'srcset' => false, 'sizes' => false);
    if ($attachment = get_post($attachment_id)) {
        $props['title'] = trim(strip_tags($attachment->post_title));
        $props['caption'] = trim(strip_tags($attachment->post_excerpt));
        $props['url'] = wp_get_attachment_url($attachment_id);
        $props['alt'] = trim(strip_tags(get_post_meta($attachment_id, '_wp_attachment_image_alt', true)));
        // Large version.
        $src = wp_get_attachment_image_src($attachment_id, 'large');
        $props['full_src'] = $src[0];
        $props['full_src_w'] = $src[1];
        $props['full_src_h'] = $src[2];
        // Image source.
        $src = wp_get_attachment_image_src($attachment_id, 'shop_single');
        $props['src'] = $src[0];
        $props['src_w'] = $src[1];
        $props['src_h'] = $src[2];
        $props['srcset'] = function_exists('wp_get_attachment_image_srcset') ? wp_get_attachment_image_srcset($attachment_id, 'shop_single') : false;
        $props['sizes'] = function_exists('wp_get_attachment_image_sizes') ? wp_get_attachment_image_sizes($attachment_id, 'shop_single') : false;
        // Alt text fallbacks
        $props['alt'] = empty($props['alt']) ? $props['caption'] : $props['alt'];
        $props['alt'] = empty($props['alt']) ? trim(strip_tags($attachment->post_title)) : $props['alt'];
        $props['alt'] = empty($props['alt']) && $product ? trim(strip_tags(get_the_title($product->ID))) : $props['alt'];
    }
    return $props;
}
function ubik_imagery_img($id = '', $size = '', $alt = '', $context = '')
{
    // Return a placeholder if we have no ID to work with; this is up to the theme to style
    if (empty($id)) {
        return array(apply_filters('ubik_imagery_placeholder', '<div class="no-image"></div>'), 0, 0);
    }
    // Initialize
    $html = $src = $srcset = $sizes = $width = $height = $dimensions = $attributes = '';
    $class = array('ubik-img');
    $size = apply_filters('ubik_imagery_size', $size);
    // Custom replacement for get_image_tag(); roll your own instead of using $html = get_image_tag( $id, $alt, $title, $align, $size );
    list($src, $width, $height, $is_intermediate) = image_downsize($id, $size);
    // Add a styling hook for square images
    if (ubik_imagery_size_is_square($size)) {
        $class[] = 'square';
    }
    // Another size was requested but WP returned the full image
    if (!$is_intermediate && $size !== 'full') {
        $size = 'full';
    }
    // Provide an opportunity to filter the `src` attribute; here you can clear it, substitute a blank image, or do something else
    $src = esc_attr(apply_filters('ubik_imagery_src', $src, $id, $size));
    if (!empty($src)) {
        $src = 'src="' . $src . '" ';
    }
    // `srcset` is easy; no filter here, just use the WordPress 4.4+ standard
    $srcset = wp_get_attachment_image_srcset($id, $size);
    if (!empty($srcset)) {
        $srcset = 'srcset="' . esc_attr($srcset) . '" ';
    }
    // `sizes` is slightly more complicated; these must be set at the theme level
    $sizes = ubik_imagery_sizes_attribute($size, $width, $context);
    if (!empty($sizes)) {
        $sizes = 'sizes="' . esc_attr($sizes) . '" ';
    }
    // Class
    $class = implode(' ', apply_filters('ubik_imagery_img_class', $class));
    if (!empty($class)) {
        $class = 'class="' . esc_attr($class) . '"';
    }
    // Aspect ratio
    $ratio = ubik_imagery_sizes_ratio($width, $height);
    if (!empty($ratio)) {
        $ratio = 'data-aspect-ratio="' . esc_attr($ratio) . '"';
    }
    // Attributes
    $attributes = implode(' ', apply_filters('ubik_imagery_img_attributes', array('id' => 'id="wp-image-' . esc_attr($id) . '"', 'data-id' => 'data-id="' . esc_attr($id) . '"', 'class' => $class, 'ratio' => $ratio, 'schema' => 'itemprop="contentUrl"', 'alt' => 'alt="' . $alt . '"')));
    // Return an array with the final width/height so these values can be passed up to the wrapper element for certain CSS styling tricks
    return array(apply_filters('ubik_imagery_img', '<img ' . apply_filters('ubik_imagery_src_html', $src) . apply_filters('ubik_imagery_srcset_html', $srcset) . apply_filters('ubik_imagery_sizes_html', $sizes) . apply_filters('ubik_imagery_dimensions', image_hwstring($width, $height), $width, $height) . $attributes . '>'), $width, $height);
}
            //
            // case 'video':
            // 	$video = get_post_meta( $post_ID, 'uxr_event_flexible_content_' . $count . '_video', true);
            // 	if ( isset($video) && !empty($video) ) :
            // 		echo apply_filters('the_content', $video) . "\n";
            // 	endif;
            // break;
            //
            // Image
            //
            case 'fullwidth_image':
                $image_ID = get_post_meta($post_ID, 'uxr_event_flexible_content_' . $count . '_fullwidth_image', true);
                if (isset($image_ID) && !empty($image_ID)) {
                    // Image source
                    $img_src = wp_get_attachment_image_url($image_ID, 'large');
                    $img_srcset = wp_get_attachment_image_srcset($image_ID, 'large');
                    $img_sizes = wp_get_attachment_image_sizes($image_ID, 'large');
                    // Image meta
                    $image_meta = get_posts(array('p' => $image_ID, 'post_type' => 'attachment'));
                    $image_caption = $image_meta[0]->post_excerpt;
                    $image_more_meta = wp_get_attachment_metadata($image_ID, 'large');
                    echo "\t" . '</div>' . "\n";
                    echo '</div>' . "\n";
                    echo '<img src="' . esc_url($img_src) . '" srcset="' . esc_attr($img_srcset) . '" sizes="' . esc_attr($img_sizes) . '" alt="" class="uxr-asset-fullwidth" />';
                    echo '<div class="uxr-grid-container">' . "\n";
                    echo "\t" . '<div class="uxr-contrib">' . "\n";
                }
                break;
        }
    }
}
 /**
  * Get post featured image
  *
  * @since 1.0.0
  *
  * @param  array  $args Array, containing size and format options.
  *
  * @return string
  */
 public function post_featured_image(array $args = array())
 {
     $size = $this->image_sizes['small'];
     $format = '<div style="background-image: url(\'%1$s\');"><img src="%1$s" %2$s srcset="%3$s"></div>';
     if (true === isset($args['size']) && false === empty($args['size'])) {
         $size = $args['size'];
     }
     if (true === isset($args['format']) && false === empty($args['format'])) {
         $format = $args['format'];
     }
     $atts = '';
     global $_wp_additional_image_sizes;
     if (has_post_thumbnail()) {
         $atts = sprintf('width="%1$s" height="%2$s"', $_wp_additional_image_sizes[$size]['width'], $_wp_additional_image_sizes[$size]['height']);
         $image_url = get_the_post_thumbnail_url(null, $size);
     } else {
         $width = get_option("{$size}_size_w");
         $height = get_option("{$size}_size_h");
         $image_url = "http://fakeimg.pl/{$width}x{$height}";
     }
     $image_url = esc_url($image_url);
     $srcset = wp_get_attachment_image_srcset(get_post_thumbnail_id(), $size);
     return sprintf($format, $image_url, $atts, $srcset);
 }
Example #13
0
 /**
  * Get uploaded file information
  *
  * @param int   $file_id Attachment image ID (post ID). Required.
  * @param array $args    Array of arguments (for size).
  *
  * @return array|bool False if file not found. Array of image info on success
  */
 static function file_info($file_id, $args = array())
 {
     $args = wp_parse_args($args, array('size' => 'thumbnail'));
     $img_src = wp_get_attachment_image_src($file_id, $args['size']);
     if (!$img_src) {
         return false;
     }
     $attachment = get_post($file_id);
     $path = get_attached_file($file_id);
     return array('ID' => $file_id, 'name' => basename($path), 'path' => $path, 'url' => $img_src[0], 'width' => $img_src[1], 'height' => $img_src[2], 'full_url' => wp_get_attachment_url($file_id), 'title' => $attachment->post_title, 'caption' => $attachment->post_excerpt, 'description' => $attachment->post_content, 'alt' => get_post_meta($file_id, '_wp_attachment_image_alt', true), 'srcset' => wp_get_attachment_image_srcset($file_id));
 }
 // $imageid = get_post_meta( $hero->ID, 'fauval_sliderid', true );
 $imageid = get_post_meta($hero->ID, 'fauval_slider_image', true);
 $slidersrc = '';
 $slidersrcset = '';
 if (isset($imageid) && $imageid > 0) {
     $sliderimage = wp_get_attachment_image_src($imageid, 'hero');
     $imgdata = fau_get_image_attributs($imageid);
     $copyright = trim(strip_tags($imgdata['credits']));
     $slidersrcset = wp_get_attachment_image_srcset($imageid, 'hero');
 } else {
     $post_thumbnail_id = get_post_thumbnail_id($hero->ID);
     if ($post_thumbnail_id) {
         $sliderimage = wp_get_attachment_image_src($post_thumbnail_id, 'hero');
         $imgdata = fau_get_image_attributs($post_thumbnail_id);
         $copyright = trim(strip_tags($imgdata['credits']));
         $slidersrcset = wp_get_attachment_image_srcset($post_thumbnail_id, 'hero');
     }
 }
 if (!$sliderimage || empty($sliderimage[0])) {
     $slidersrc = '<img src="' . fau_esc_url($options['src-fallback-slider-image']) . '" width="' . $options['slider-image-width'] . '" height="' . $options['slider-image-height'] . '" alt="">';
 } else {
     $slidersrc = '<img src="' . fau_esc_url($sliderimage[0]) . '" width="' . $options['slider-image-width'] . '" height="' . $options['slider-image-height'] . '" alt=""';
     if ($slidersrcset) {
         $slidersrc .= ' srcset="' . $slidersrcset . '"';
     }
     $slidersrc .= '>';
 }
 echo $slidersrc . "\n";
 if ($options['advanced_display_hero_credits'] == true && !empty($copyright)) {
     echo '<p class="credits">' . $copyright . "</p>";
 }
Example #15
0
    /**
     * @ticket 33641
     */
    function test_wp_make_content_images_responsive()
    {
        $srcset = sprintf('srcset="%s"', wp_get_attachment_image_srcset(self::$large_id, 'medium'));
        $sizes = sprintf('sizes="%s"', wp_get_attachment_image_sizes(self::$large_id, 'medium'));
        // Function used to build HTML for the editor.
        $img = get_image_tag(self::$large_id, '', '', '', 'medium');
        $img_no_size = str_replace('size-', '', $img);
        $img_no_size_id = str_replace('wp-image-', 'id-', $img_no_size);
        // Manually add srcset and sizes to the markup from get_image_tag();
        $respimg = preg_replace('|<img ([^>]+) />|', '<img $1 ' . $srcset . ' ' . $sizes . ' />', $img);
        $respimg_no_size = preg_replace('|<img ([^>]+) />|', '<img $1 ' . $srcset . ' ' . $sizes . ' />', $img_no_size);
        $content = '<p>Welcome to WordPress!  This post contains important information.  After you read it, you can make it private to hide it from visitors but still have the information handy for future reference.</p>
			<p>First things first:</p>

			%1$s

			<ul>
			<li><a href="http://wordpress.org" title="Subscribe to the WordPress mailing list for Release Notifications">Subscribe to the WordPress mailing list for release notifications</a></li>
			</ul>

			%2$s

			<p>As a subscriber, you will receive an email every time an update is available (and only then).  This will make it easier to keep your site up to date, and secure from evildoers.<br />
			When a new version is released, <a href="http://wordpress.org" title="If you are already logged in, this will take you directly to the Dashboard">log in to the Dashboard</a> and follow the instructions.<br />
			Upgrading is a couple of clicks!</p>

			%3$s

			<p>Then you can start enjoying the WordPress experience:</p>
			<ul>
			<li>Edit your personal information at <a href="http://wordpress.org" title="Edit settings like your password, your display name and your contact information">Users &#8250; Your Profile</a></li>
			<li>Start publishing at <a href="http://wordpress.org" title="Create a new post">Posts &#8250; Add New</a> and at <a href="http://wordpress.org" title="Create a new page">Pages &#8250; Add New</a></li>
			<li>Browse and install plugins at <a href="http://wordpress.org" title="Browse and install plugins at the official WordPress repository directly from your Dashboard">Plugins &#8250; Add New</a></li>
			<li>Browse and install themes at <a href="http://wordpress.org" title="Browse and install themes at the official WordPress repository directly from your Dashboard">Appearance &#8250; Add New Themes</a></li>
			<li>Modify and prettify your website&#8217;s links at <a href="http://wordpress.org" title="For example, select a link structure like: http://example.com/1999/12/post-name">Settings &#8250; Permalinks</a></li>
			<li>Import content from another system or WordPress site at <a href="http://wordpress.org" title="WordPress comes with importers for the most common publishing systems">Tools &#8250; Import</a></li>
			<li>Find answers to your questions at the <a href="http://wordpress.orgs" title="The official WordPress documentation, maintained by the WordPress community">WordPress Codex</a></li>
			</ul>';
        $content_unfiltered = sprintf($content, $img, $img_no_size, $img_no_size_id);
        $content_filtered = sprintf($content, $respimg, $respimg_no_size, $img_no_size_id);
        $this->assertSame($content_filtered, wp_make_content_images_responsive($content_unfiltered));
    }
 /**
  * Get post attached image.
  *
  * @since  1.0.0
  * @param  int $id post id.
  * @param  array, string
  * @return string(HTML-formatted).
  */
 public function get_image($id, $size, $placeholder_attr, $only_url = false)
 {
     // Place holder defaults attr
     $default_placeholder_attr = apply_filters('king_news_news_smart_box_placeholder_default_args', array('width' => 900, 'height' => 500, 'background' => '000', 'foreground' => 'fff', 'title' => '', 'class' => ''));
     $placeholder_attr = wp_parse_args($placeholder_attr, $default_placeholder_attr);
     $image = '';
     // Check the attached image, if not attached - function replaces on the placeholder
     if (has_post_thumbnail($id)) {
         $thumbnail_id = get_post_thumbnail_id(intval($id));
         $attachment_image = wp_get_attachment_image_src($thumbnail_id, $size);
         if ($only_url) {
             return $attachment_image[0];
         }
         $html_attrs = array('class' => 'swiper-image', 'src' => $attachment_image[0], 'width' => $attachment_image[1], 'height' => $attachment_image[2], 'alt' => get_the_title(), 'srcset' => wp_get_attachment_image_srcset($thumbnail_id, $size));
         $image_html_attrs = $this->prepare_atts($html_attrs);
         $image = sprintf('<img %s>', $image_html_attrs);
     } else {
         $placeholder_link = 'http://fakeimg.pl/' . $placeholder_attr['width'] . 'x' . $placeholder_attr['height'] . '/' . $placeholder_attr['background'] . '/' . $placeholder_attr['foreground'] . '/?text=' . $placeholder_attr['title'] . '';
         $image = '<img class="sp-image ' . $placeholder_attr['class'] . '" src="' . $placeholder_link . '" alt="' . $placeholder_attr['title'] . '">';
     }
     return $image;
 }
Example #17
0
/**
 * Retrieves the value for an image attachment’s ‘srcset’ attribute.
 *
 * @since  1.0.0
 * @access protected
 * @param  int   $id The ID of the current attachment.
 * @param  array $args Arguments for how to load and display the image.
 * @return false|string A 'srcset' value string or false.
 */
function _carelib_image_get_srcset($id, $args)
{
    if (!$args['responsive'] || !function_exists('wp_get_attachment_image_srcset')) {
        return false;
    }
    return wp_get_attachment_image_srcset($id, $args['size']);
}
Example #18
0
 function widget($args, $instance)
 {
     extract($args);
     $title = apply_filters('widget_title', $instance['title']);
     $largeitems = intval($instance['largeitems']);
     $mediumitems = intval($instance['mediumitems']);
     $thumbnailitems = intval($instance['thumbnailitems']);
     $listitems = intval($instance['listitems']);
     $showexcerpt = $instance['showexcerpt'];
     $acf_key = "widget_" . $this->id_base . "-" . $this->number . "_pin_stories";
     $top_slot = get_option($acf_key);
     $acf_key = "widget_" . $this->id_base . "-" . $this->number . "_exclude_stories";
     $exclude = get_option($acf_key);
     $acf_key = "widget_" . $this->id_base . "-" . $this->number . "_news_listing_news_type";
     $newstypes = get_option($acf_key);
     if (!$title) {
         $title = "no_title_" . $id;
     }
     $moretitle = $instance['moretitle'];
     global $post;
     $removenews = get_transient('cached_removenews');
     if (!$removenews || !is_array($removenews)) {
         set_transient('cached_removenews', "wait", 60 * 3);
         //process expired news
         $tzone = get_option('timezone_string');
         date_default_timezone_set($tzone);
         $tdate = date('Ymd');
         $oldnews = query_posts(array('post_type' => 'news', 'meta_query' => array(array('key' => 'news_expiry_date', 'value' => $tdate, 'compare' => '<='))));
         if (count($oldnews) > 0) {
             foreach ($oldnews as $old) {
                 if ($tdate == date('Ymd', strtotime(get_post_meta($old->ID, 'news_expiry_date', true)))) {
                     // if expiry today, check the time
                     if (date('H:i:s', strtotime(get_post_meta($old->ID, 'news_expiry_time', true))) > date('H:i:s')) {
                         continue;
                     }
                 }
                 $expiryaction = get_post_meta($old->ID, 'news_expiry_action', true);
                 if ($expiryaction == 'Revert to draft status') {
                     $my_post = array();
                     $my_post['ID'] = $old->ID;
                     $my_post['post_status'] = 'draft';
                     wp_update_post($my_post);
                     delete_post_meta($old->ID, 'news_expiry_date');
                     delete_post_meta($old->ID, 'news_expiry_time');
                     delete_post_meta($old->ID, 'news_expiry_action');
                     delete_post_meta($old->ID, 'news_auto_expiry');
                     if (function_exists('wp_cache_post_change')) {
                         wp_cache_post_change($old->ID);
                     }
                     if (function_exists('wp_cache_post_change')) {
                         wp_cache_post_change($my_post);
                     }
                 }
                 if ($expiryaction == 'Change to regular news') {
                     set_post_format($old->ID, '');
                     delete_post_meta($old->ID, 'news_expiry_date');
                     delete_post_meta($old->ID, 'news_expiry_time');
                     delete_post_meta($old->ID, 'news_expiry_action');
                     delete_post_meta($old->ID, 'news_auto_expiry');
                     if (function_exists('wp_cache_post_change')) {
                         wp_cache_post_change($old->ID);
                     }
                 }
                 if ($expiryaction == 'Move to trash') {
                     $my_post = array();
                     $my_post['ID'] = $old->ID;
                     $my_post['post_status'] = 'trash';
                     delete_post_meta($old->ID, 'news_expiry_date');
                     delete_post_meta($old->ID, 'news_expiry_time');
                     delete_post_meta($old->ID, 'news_expiry_action');
                     delete_post_meta($old->ID, 'news_auto_expiry');
                     wp_update_post($my_post);
                     if (function_exists('wp_cache_post_change')) {
                         wp_cache_post_change($old->ID);
                     }
                     if (function_exists('wp_cache_post_change')) {
                         wp_cache_post_change($my_post);
                     }
                 }
             }
         }
         wp_reset_query();
     }
     echo $before_widget;
     if ($title && $title != "no_title_" . $id) {
         echo $before_title;
         echo $title;
         echo $after_title;
     }
     echo '<div id="ht-feature-news">';
     //formulate grid of news stories and formats
     $totalstories = $largeitems + $mediumitems + $thumbnailitems + $listitems;
     $newsgrid = array();
     for ($i = 1; $i <= $totalstories; $i++) {
         if ($i <= $largeitems) {
             $newsgrid[] = "L";
         } elseif ($i <= $largeitems + $mediumitems) {
             $newsgrid[] = "M";
         } elseif ($i <= $largeitems + $mediumitems + $thumbnailitems) {
             $newsgrid[] = "T";
         } elseif ($i <= $largeitems + $mediumitems + $thumbnailitems + $listitems) {
             $newsgrid[] = "Li";
         }
     }
     $siteurl = site_url();
     //manual override news stories
     //display sticky top news stories
     $num_top_slots = count($top_slot);
     $to_fill = $totalstories - $num_top_slots;
     $k = -1;
     $alreadydone = array();
     if ($num_top_slots > 0) {
         foreach ((array) $top_slot as $thisslot) {
             if (!$thisslot) {
                 continue;
             }
             $slot = get_post($thisslot);
             if ($slot->post_status != 'publish') {
                 continue;
             }
             $k++;
             $alreadydone[] = $slot->ID;
             if (function_exists('get_video_thumbnail')) {
                 $videostill = get_video_thumbnail($slot->ID);
             }
             $thistitle = $slot->post_title;
             $thisURL = get_permalink($slot->ID);
             $video = 0;
             if (has_post_format('video', $slot->ID)) {
                 $video = apply_filters('the_content', get_post_meta($slot->ID, 'news_video_url', true));
             }
             if ($newsgrid[$k] == "L") {
                 if ($video) {
                     echo $video;
                 } elseif (has_post_thumbnail($post->ID)) {
                     $img_srcset = wp_get_attachment_image_srcset(get_post_thumbnail_id($post->ID), array('newshead', 'large', 'medium', 'thumbnail'));
                     $img_sizes = wp_get_attachment_image_sizes(get_post_thumbnail_id($post->ID), 'newshead');
                     echo "<a href='{$thisURL}'>" . get_the_post_thumbnail($post->ID, 'newshead', array('class' => 'img-responsive')) . "</a>";
                     echo wpautop("<p class='news_date'>" . get_post_thumbnail_caption() . "</p>");
                 }
             }
             if ($newsgrid[$k] == "M") {
                 $image_uri = wp_get_attachment_image_src(get_post_thumbnail_id($slot->ID), 'newsmedium');
                 if ($image_uri != "") {
                     echo "<a href='{$thisURL}'><img class='img img-responsive' src='{$image_uri[0]}' width='{$image_uri[1]}' height='{$image_uri[2]}' alt='" . govintranetpress_custom_title($slot->post_title) . "' /></a>";
                 }
             }
             if ($newsgrid[$k] == "T") {
                 $image_uri = "<a class='pull-right' href='" . $thisURL . "'>" . get_the_post_thumbnail($slot->ID, 'thumbnail', array('class' => 'media-object hidden-xs')) . "</a>";
                 if ($image_uri != "") {
                     $image_url = $image_uri;
                 }
             }
             $thisdate = $slot->post_date;
             $post = get_post($slot->ID);
             setup_postdata($post);
             $thisexcerpt = get_the_excerpt();
             $thisdate = date(get_option('date_format'), strtotime($thisdate));
             $ext_icon = '';
             if (get_post_format($slot->ID) == 'link') {
                 $ext_icon = "<span class='dashicons dashicons-migrate'></span> ";
             }
             if ($newsgrid[$k] == "T") {
                 echo "<div class='media'>" . $image_url;
             }
             echo "<div class='media-body'>";
             echo "<h3 class='noborder'>" . $ext_icon . "<a href='" . $thisURL . "'>" . $thistitle . "</a>" . $ext_icon . "</h3>";
             if ($newsgrid[$k] == "Li") {
                 echo "<p>";
                 echo '<span class="listglyph">' . get_the_date(get_option('date_format'));
                 echo '</span> ';
                 echo " <span class='badge'>Featured</span>";
                 if (get_comments_number()) {
                     echo "<a href='" . $thisURL . "#comments'>";
                     printf(_n('<span class="badge">1 comment</span>', '<span class="badge">%d comments</span>', get_comments_number(), 'govintranet'), get_comments_number());
                     echo "</a>";
                 }
                 echo " <a class='news_date more' href='{$thisURL}' title='{$thistitle}'>" . __('Full story', 'govintranet') . " <span class='dashicons dashicons-arrow-right-alt2'></span></a></span></p>";
             } else {
                 if ($showexcerpt == 'on') {
                     echo "<p>";
                     echo '<span class="listglyph">' . get_the_date(get_option('date_format'));
                     echo '</span> ';
                     echo " <span class='badge'>" . __('Featured', 'govitranet') . "</span>";
                     if (get_comments_number()) {
                         echo "<a href='" . $thisURL . "#comments'>";
                         printf(_n('<span class="badge">1 comment</span>', '<span class="badge">%d comments</span>', get_comments_number(), 'govintranet'), get_comments_number());
                         echo "</a>";
                     }
                     echo "</p>";
                     echo $thisexcerpt;
                     echo "<p class='news_date'><a class='more' href='{$thisURL}' title='{$thistitle}'>" . __('Full story', 'govintranet') . " <span class='dashicons dashicons-arrow-right-alt2'></span></a></p>";
                 } else {
                     echo "<p>";
                     echo '<span class="listglyph">' . get_the_date(get_option('date_format'));
                     echo '</span> ';
                     echo " <span class='badge'>" . __('Featured', 'govitranet') . "</span>";
                     if (get_comments_number()) {
                         echo "<a href='" . $thisURL . "#comments'>";
                         printf(_n('<span class="badge">1 comment</span>', '<span class="badge">%d comments</span>', get_comments_number(), 'govintranet'), get_comments_number());
                         echo "</a>";
                     }
                     echo " <a class='news_date more' href='{$thisURL}' title='{$thistitle}'>" . __('Full story', 'govintranet') . " <span class='dashicons dashicons-arrow-right-alt2'></span></a></span></p>";
                 }
             }
             echo "</div>";
             if ($newsgrid[$k] == "T") {
                 echo "</div>";
             }
             echo "<hr class='light' />\n";
         }
     }
     //end of stickies
     //display remaining stories
     $cquery = array('post_type' => 'news', 'posts_per_page' => $totalstories, 'post__not_in' => $exclude, 'tax_query' => array(array('taxonomy' => 'post_format', 'field' => 'slug', 'terms' => array('post-format-status'), "operator" => "NOT IN")));
     if ($newstypes) {
         $cquery['tax_query'] = array("relation" => "AND", array('taxonomy' => 'news-type', 'terms' => $newstypes, 'field' => 'id'), array('taxonomy' => 'post_format', 'field' => 'slug', 'terms' => array('post-format-status'), "operator" => "NOT IN"));
     }
     $news = new WP_Query($cquery);
     if ($news->post_count == 0) {
         echo "Nothing to show.";
     }
     global $post;
     while ($news->have_posts()) {
         $news->the_post();
         $theid = get_the_id();
         if (in_array($theid, $alreadydone)) {
             //don't show if already in stickies
             continue;
         }
         $k++;
         if ($k >= $totalstories) {
             break;
         }
         $thistitle = get_the_title($theid);
         $thisURL = get_permalink($theid);
         $video = 0;
         if (has_post_format('video', $theid)) {
             $video = apply_filters('the_content', get_post_meta($theid, 'news_video_url', true));
         }
         if ($newsgrid[$k] == "L") {
             if ($video) {
                 echo $video;
             } elseif (has_post_thumbnail($post->ID)) {
                 $img_srcset = wp_get_attachment_image_srcset(get_post_thumbnail_id($post->ID), array('newshead', 'large', 'medium', 'thumbnail'));
                 $img_sizes = wp_get_attachment_image_sizes(get_post_thumbnail_id($post->ID), 'newshead');
                 echo "<a href='{$thisURL}'>" . get_the_post_thumbnail($post->ID, 'newshead', array('class' => 'img-responsive')) . "</a>";
                 echo wpautop("<p class='news_date'>" . get_post_thumbnail_caption() . "</p>");
             }
         }
         if ($newsgrid[$k] == "M") {
             $image_uri = wp_get_attachment_image_src(get_post_thumbnail_id($theid), 'newsmedium');
             if ($image_uri != "") {
                 echo "<a href='{$thisURL}'><img class='img img-responsive' src='{$image_uri[0]}' width='{$image_uri[1]}' height='{$image_uri[2]}' alt='" . govintranetpress_custom_title($post->post_title) . "' /></a>";
             }
         }
         if ($newsgrid[$k] == "T") {
             $image_uri = "<a class='pull-right' href='{$thisURL}'>" . get_the_post_thumbnail($theid, 'thumbnail', array('class' => 'media-object hidden-xs')) . "</a>";
             if ($image_uri != "") {
                 $image_url = $image_uri;
             }
         }
         $thisdate = get_the_date(get_option('date_format'));
         $thisexcerpt = get_the_excerpt();
         $ext_icon = '';
         if ($newsgrid[$k] == "T") {
             echo "<div class='media'>" . $image_url;
         }
         echo "<div class='media-body feature-news-" . strtolower($newsgrid[$k]) . "'>";
         if (get_post_format($theid) == 'link') {
             $ext_icon = "<i class='dashicons dashicons-migrate'></i> ";
         }
         echo "<h3 class='noborder'><a href='" . $thisURL . "'>" . $thistitle . "</a> " . $ext_icon . "</h3>";
         if ($newsgrid[$k] == "Li") {
             echo "<p>";
             echo '<span class="listglyph">' . get_the_date(get_option('date_format'));
             echo '</span> ';
             if (get_comments_number()) {
                 echo "<a href='" . $thisURL . "#comments'>";
                 printf(_n('<span class="badge">1 comment</span>', '<span class="badge">%d comments</span>', get_comments_number(), 'govintranet'), get_comments_number());
                 echo "</a>";
             }
             echo "</p>";
         } else {
             if ($showexcerpt == 'on') {
                 echo "<p>";
                 echo '<span class="listglyph">' . get_the_date(get_option('date_format'));
                 echo '</span> ';
                 if (get_comments_number()) {
                     echo " <a href='" . $thisURL . "#comments'>";
                     printf(_n('<span class="badge">1 comment</span>', '<span class="badge">%d comments</span>', get_comments_number(), 'govintranet'), get_comments_number());
                     echo "</a>";
                 }
                 echo "</p>";
                 echo $thisexcerpt;
                 echo "<p class='news_date'><a class='more' href='{$thisURL}' title='{$thistitle}'>" . __('Full story', 'govintranet') . " <span class='dashicons dashicons-arrow-right-alt2'></span></a></p>";
             } else {
                 echo "<p>";
                 echo '<span class="listglyph">' . get_the_date(get_option('date_format'));
                 echo '</span> ';
                 if (get_comments_number()) {
                     echo " <a href='" . $thisURL . "#comments'>";
                     printf(_n('<span class="badge">1 comment</span>', '<span class="badge">%d comments</span>', get_comments_number(), 'govintranet'), get_comments_number());
                     echo "</a>";
                 }
                 echo " <a class='news_date more' href='{$thisURL}' title='{$thistitle}'>" . __('Full story', 'govintranet') . " <span class='dashicons dashicons-arrow-right-alt2'></span></a></p>";
             }
         }
         echo "</div>";
         if ($newsgrid[$k] == "T") {
             echo "</div>";
         }
         echo "<hr class='light' />\n";
     }
     wp_reset_query();
     $landingpage = get_option('options_module_news_page');
     if (!$landingpage) {
         $landingpage_link_text = 'news';
         $landingpage = site_url() . '/newspage/';
     } else {
         $landingpage_link_text = get_the_title($landingpage[0]);
         $landingpage = get_permalink($landingpage[0]);
     }
     if (!$moretitle) {
         $moretitle = $title;
     }
     if ($moretitle = "no_title_" . $id) {
         $moretitle = __("More", "govintranet");
     }
     if (is_array($newstypes) && count($newstypes) < 2) {
         $term = intval($newstypes[0]);
         $landingpage = get_term_link($term, 'news-type');
         echo '<p class="more-updates"><strong><a title="' . $landingpage_link_text . '" class="small" href="' . $landingpage . '">' . $moretitle . '</a></strong> <span class="dashicons dashicons-arrow-right-alt2"></span></p>';
     } else {
         $landingpage_link_text = $moretitle;
         echo '<p class="more-updates"><strong><a title="' . $landingpage_link_text . '" class="small" href="' . $landingpage . '">' . $landingpage_link_text . '</a></strong> <span class="dashicons dashicons-arrow-right-alt2"></span></p>';
     }
     echo "<div class='clearfix'></div>";
     echo "</div>";
     echo $after_widget;
 }
Example #19
0
    echo $thumbs['alt'];
    ?>
" 
					title="<?php 
    echo $thumbs['title'];
    ?>
"
				>
			</label>
		</li>
	<?php 
    $i = 1;
    while (the_repeater_field('galeria_de_imagenes')) {
        $thumb = get_sub_field('gallery_image');
        $slide_src = wp_get_attachment_image_url($thumb['id'], 'full-size');
        $slides_srcset = wp_get_attachment_image_srcset($thumb['id'], 'full-size');
        ?>
		<li class="slider__extra-images--thumb">
			<label for="slider__image--<?php 
        echo $i;
        ?>
" class="slider__extra-images--thumbnail" id="img-dot-<?php 
        echo $i;
        ?>
">
				<img
					src="<?php 
        echo esc_url($img_src);
        ?>
"
					srcset="<?php 
 /**
  * render image tag
  *
  * @param int $attachment_id post id of the image
  * @since 1.6.10
  */
 public function create_image_tag($attachment_id)
 {
     $image = wp_get_attachment_image_src($attachment_id, 'full');
     if ($image) {
         list($src, $width, $height) = $image;
         $hwstring = image_hwstring($width, $height);
         $attachment = get_post($attachment_id);
         $alt = trim(strip_tags(get_post_meta($attachment_id, '_wp_attachment_image_alt', true)));
         $title = trim(strip_tags($attachment->post_title));
         // Finally, use the title
         global $wp_current_filter;
         $more_attributes = '';
         // create srcset and sizes attributes if we are in the the_content filter and in WordPress 4.4
         if (isset($wp_current_filter) && in_array('the_content', $wp_current_filter) && !defined('ADVADS_DISABLE_RESPONSIVE_IMAGES')) {
             if (function_exists('wp_get_attachment_image_srcset')) {
                 $more_attributes .= ' srcset=\'' . wp_get_attachment_image_srcset($attachment_id, 'full') . '\'';
             }
             if (function_exists('wp_get_attachment_image_sizes')) {
                 $more_attributes .= ' sizes=\'' . wp_get_attachment_image_sizes($attachment_id, 'full') . '\'';
             }
         }
         echo rtrim("<img {$hwstring}") . " src='{$src}' alt='{$alt}' title='{$title}' {$more_attributes}/>";
     }
 }
Example #21
0
File: media.php Project: nkeat12/dv
    /**
     * @ticket 33641
     */
    function test_wp_make_content_images_responsive()
    {
        $image_meta = wp_get_attachment_metadata(self::$large_id);
        $size_array = $this->_get_image_size_array_from_name('medium');
        $srcset = sprintf('srcset="%s"', wp_get_attachment_image_srcset(self::$large_id, $size_array, $image_meta));
        $sizes = sprintf('sizes="%s"', wp_get_attachment_image_sizes(self::$large_id, $size_array, $image_meta));
        // Function used to build HTML for the editor.
        $img = get_image_tag(self::$large_id, '', '', '', 'medium');
        $img_no_size_in_class = str_replace('size-', '', $img);
        $img_no_width_height = str_replace(' width="' . $size_array[0] . '"', '', $img);
        $img_no_width_height = str_replace(' height="' . $size_array[1] . '"', '', $img_no_width_height);
        $img_no_size_id = str_replace('wp-image-', 'id-', $img);
        $img_with_sizes_attr = str_replace('<img ', '<img sizes="99vw" ', $img);
        $img_xhtml = str_replace(' />', '/>', $img);
        $img_html5 = str_replace(' />', '>', $img);
        // Manually add srcset and sizes to the markup from get_image_tag();
        $respimg = preg_replace('|<img ([^>]+) />|', '<img $1 ' . $srcset . ' ' . $sizes . ' />', $img);
        $respimg_no_size_in_class = preg_replace('|<img ([^>]+) />|', '<img $1 ' . $srcset . ' ' . $sizes . ' />', $img_no_size_in_class);
        $respimg_no_width_height = preg_replace('|<img ([^>]+) />|', '<img $1 ' . $srcset . ' ' . $sizes . ' />', $img_no_width_height);
        $respimg_with_sizes_attr = preg_replace('|<img ([^>]+) />|', '<img $1 ' . $srcset . ' />', $img_with_sizes_attr);
        $respimg_xhtml = preg_replace('|<img ([^>]+)/>|', '<img $1 ' . $srcset . ' ' . $sizes . ' />', $img_xhtml);
        $respimg_html5 = preg_replace('|<img ([^>]+)>|', '<img $1 ' . $srcset . ' ' . $sizes . ' />', $img_html5);
        $content = '
			<p>Image, standard. Should have srcset and sizes.</p>
			%1$s

			<p>Image, no size class. Should have srcset and sizes.</p>
			%2$s

			<p>Image, no width and height attributes. Should have srcset and sizes (from matching the file name).</p>
			%3$s

			<p>Image, no attachment ID class. Should NOT have srcset and sizes.</p>
			%4$s

			<p>Image, with sizes attribute. Should NOT have two sizes attributes.</p>
			%5$s

			<p>Image, XHTML 1.0 style (no space before the closing slash). Should have srcset and sizes.</p>
			%6$s

			<p>Image, HTML 5.0 style. Should have srcset and sizes.</p>
			%7$s';
        $content_unfiltered = sprintf($content, $img, $img_no_size_in_class, $img_no_width_height, $img_no_size_id, $img_with_sizes_attr, $img_xhtml, $img_html5);
        $content_filtered = sprintf($content, $respimg, $respimg_no_size_in_class, $respimg_no_width_height, $img_no_size_id, $respimg_with_sizes_attr, $respimg_xhtml, $respimg_html5);
        $this->assertSame($content_filtered, wp_make_content_images_responsive($content_unfiltered));
    }
Example #22
0
/**
 * Adds 'srcset' and 'sizes' attributes to an existing 'img' element.
 *
 * @since 4.4.0
 *
 * @see wp_get_attachment_image_srcset()
 * @see wp_get_attachment_image_sizes()
 *
 * @param string $image An HTML 'img' element to be filtered.
 * @return string Converted 'img' element with `srcset` and `sizes` attributes added.
 */
function wp_img_add_srcset_and_sizes($image)
{
    // Return early if a 'srcset' attribute already exists.
    if (false !== strpos($image, ' srcset="')) {
        return $image;
    }
    // Parse id, size, width, and height from the `img` element.
    $id = preg_match('/wp-image-([0-9]+)/i', $image, $match_id) ? (int) $match_id[1] : false;
    $size = preg_match('/size-([^\\s|"]+)/i', $image, $match_size) ? $match_size[1] : false;
    $width = preg_match('/ width="([0-9]+)"/', $image, $match_width) ? (int) $match_width[1] : false;
    $height = preg_match('/ height="([0-9]+)"/', $image, $match_height) ? (int) $match_height[1] : false;
    if ($id && false === $size) {
        $size = array($width, $height);
    }
    /*
     * If attempts to parse the size value failed, attempt to use the image
     * metadata to match the 'src' against the available sizes for an attachment.
     */
    if (!$size && !empty($id) && is_array($meta = wp_get_attachment_metadata($id))) {
        // Parse the image src value from the img element.
        $src = preg_match('/src="([^"]+)"/', $image, $match_src) ? $match_src[1] : false;
        // Return early if the src value is empty.
        if (!$src) {
            return $image;
        }
        /*
         * First, see if the file is the full size image. If not, loop through
         * the intermediate sizes until we find a file that matches.
         */
        $image_filename = wp_basename($src);
        if ($image_filename === basename($meta['file'])) {
            $size = 'full';
        } else {
            foreach ($meta['sizes'] as $image_size => $image_size_data) {
                if ($image_filename === $image_size_data['file']) {
                    $size = $image_size;
                    break;
                }
            }
        }
    }
    // If ID and size, try for 'srcset' and 'sizes' and update the markup.
    if ($id && $size && ($srcset = wp_get_attachment_image_srcset($id, $size))) {
        /*
         * Pass the 'height' and 'width' to 'wp_get_attachment_image_sizes()' to avoid
         * recalculating the image size.
         */
        $args = array('height' => $height, 'width' => $width);
        $sizes = wp_get_attachment_image_sizes($id, $size, $args);
        // Format the srcset and sizes string and escape attributes.
        $srcset_and_sizes = sprintf(' srcset="%s" sizes="%s"', esc_attr($srcset), esc_attr($sizes));
        // Add srcset and sizes attributes to the image markup.
        $image = preg_replace('/<img ([^>]+)[\\s?][\\/?]>/', '<img $1' . $srcset_and_sizes . ' />', $image);
    }
    return $image;
}
Example #23
0
					<div class='breadcrumbs'>
						<?php 
        if (function_exists('bcn_display') && !is_front_page()) {
            bcn_display();
        }
        ?>
					</div>
				</div>
				<?php 
        $video = null;
        //check if a video thumbnail exists, if so we won't use it to display as a headline image
        if (function_exists('get_video_thumbnail')) {
            $video = get_video_thumbnail();
        }
        if (!$video) {
            $img_srcset = wp_get_attachment_image_srcset(get_post_thumbnail_id($post->ID), array('newshead', 'large', 'medium', 'thumbnail'));
            $img_sizes = wp_get_attachment_image_sizes(get_post_thumbnail_id($post->ID), 'newshead');
            if (has_post_thumbnail($post->ID)) {
                echo get_the_post_thumbnail($post->ID, 'newshead', array('class' => 'img-responsive'));
                echo wpautop("<p class='news_date'>" . get_post_thumbnail_caption() . "</p>");
            }
        }
        ?>

				<h1><?php 
        the_title();
        ?>
</h1>
				<?php 
        $article_date = get_the_date();
        $mainid = $post->ID;
Example #24
0
		<header id="header">
			<div class="container">
		    
			    <?php 
$header_image = get_header_image();
echo '<div class="branding" id="logo" role="banner" itemprop="publisher" itemscope itemtype="http://schema.org/Organization">';
echo '<h1>';
if (!is_front_page()) {
    echo '<a itemprop="url" rel="home" href="' . fau_esc_url(home_url('/')) . '">';
}
if (!empty($header_image)) {
    $customheader = get_custom_header();
    $attachment_id = 0;
    if (isset($customheader->attachment_id)) {
        $attachment_id = $customheader->attachment_id;
        $srcset = esc_attr(wp_get_attachment_image_srcset($attachment_id, 'full'));
    } else {
        $srcset = '';
    }
    echo '<img src="' . $header_image . '" width="' . get_custom_header()->width . '" height="' . get_custom_header()->height . '" alt="' . esc_attr(get_bloginfo('title')) . '"';
    if ($srcset) {
        echo ' srcset="' . $srcset . '"';
    }
    echo ">";
} else {
    echo "<span>" . get_bloginfo('title') . "</span>";
}
if (!is_front_page()) {
    echo "</a>";
}
echo '</h1>';
 /**
  * Returns an array of data for a variation. Used in the add to cart form.
  * @since  2.4.0
  * @param  WC_Product $variation Variation product object or ID
  * @return array
  */
 public function get_available_variation($variation)
 {
     if (is_numeric($variation)) {
         $variation = $this->get_child($variation);
     }
     if (has_post_thumbnail($variation->get_variation_id())) {
         $attachment_id = get_post_thumbnail_id($variation->get_variation_id());
         $attachment = wp_get_attachment_image_src($attachment_id, 'shop_single');
         $full_attachment = wp_get_attachment_image_src($attachment_id, 'full');
         $attachment_object = get_post($attachment_id);
         $image = $attachment ? current($attachment) : '';
         $image_link = $full_attachment ? current($full_attachment) : '';
         $image_title = get_the_title($attachment_id);
         $image_alt = trim(strip_tags(get_post_meta($attachment_id, '_wp_attachment_image_alt', true)));
         $image_caption = $attachment_object->post_excerpt;
         $image_srcset = function_exists('wp_get_attachment_image_srcset') ? wp_get_attachment_image_srcset($attachment_id, 'shop_single') : false;
         $image_sizes = function_exists('wp_get_attachment_image_sizes') ? wp_get_attachment_image_sizes($attachment_id, 'shop_single') : false;
         if (empty($image_alt)) {
             $image_alt = $image_title;
         }
     } else {
         $image = $image_link = $image_title = $image_alt = $image_srcset = $image_sizes = $image_caption = '';
     }
     $availability = $variation->get_availability();
     $availability_html = empty($availability['availability']) ? '' : '<p class="stock ' . esc_attr($availability['class']) . '">' . wp_kses_post($availability['availability']) . '</p>';
     $availability_html = apply_filters('woocommerce_stock_html', $availability_html, $availability['availability'], $variation);
     return apply_filters('woocommerce_available_variation', array('variation_id' => $variation->variation_id, 'variation_is_visible' => $variation->variation_is_visible(), 'variation_is_active' => $variation->variation_is_active(), 'is_purchasable' => $variation->is_purchasable(), 'display_price' => $variation->get_display_price(), 'display_regular_price' => $variation->get_display_price($variation->get_regular_price()), 'attributes' => $variation->get_variation_attributes(), 'image_src' => $image, 'image_link' => $image_link, 'image_title' => $image_title, 'image_alt' => $image_alt, 'image_caption' => $image_caption, 'image_srcset' => $image_srcset ? $image_srcset : '', 'image_sizes' => $image_sizes ? $image_sizes : '', 'price_html' => apply_filters('woocommerce_show_variation_price', $variation->get_price() === "" || $this->get_variation_price('min') !== $this->get_variation_price('max'), $this, $variation) ? '<span class="price">' . $variation->get_price_html() . '</span>' : '', 'availability_html' => $availability_html, 'sku' => $variation->get_sku(), 'weight' => $variation->get_weight() . ' ' . esc_attr(get_option('woocommerce_weight_unit')), 'dimensions' => $variation->get_dimensions(), 'min_qty' => 1, 'max_qty' => $variation->backorders_allowed() ? '' : $variation->get_stock_quantity(), 'backorders_allowed' => $variation->backorders_allowed(), 'is_in_stock' => $variation->is_in_stock(), 'is_downloadable' => $variation->is_downloadable(), 'is_virtual' => $variation->is_virtual(), 'is_sold_individually' => $variation->is_sold_individually() ? 'yes' : 'no', 'variation_description' => $variation->get_variation_description()), $this, $variation);
 }
Example #26
0
/**
 * return the responsive images.
 * 
 * @package lsx
 * @subpackage extras
 * @category thumbnails
 */
function lsx_get_thumbnail($size, $image_src = false)
{
    if (false === $image_src) {
        $post_id = get_the_ID();
        $post_thumbnail_id = get_post_thumbnail_id($post_id);
    } elseif (false != $image_src) {
        if (is_numeric($image_src)) {
            $post_thumbnail_id = $image_src;
        } else {
            $post_thumbnail_id = lsx_get_attachment_id_from_src($image_src);
        }
    }
    $size = apply_filters('lsx_thumbnail_size', $size);
    $img = false;
    if ($size === 'lsx-thumbnail-wide') {
        $img = wp_get_attachment_image_src($post_thumbnail_id, $size);
        $img = '<img class="attachment-responsive wp-post-image lsx-responsive" src="' . $img[0] . '" />';
    } elseif ($size === 'lsx-single-thumbnail') {
        $img = wp_get_attachment_image_srcset($post_thumbnail_id, $size);
        $img = '<img class="attachment-responsive wp-post-image lsx-responsive" srcset="' . $img . '" />';
    } else {
        $img = wp_get_attachment_image_srcset($post_thumbnail_id, $size);
    }
    return $img;
}
Example #27
0
<?php

get_header();
$img_srcset = wp_get_attachment_image_srcset($attachment_id, 'medium');
if (get_theme_mod('mt_header_image')) {
    ?>
<div>
    <div class="container-fluid container-height container-top">
        <div class="row container-height">
            <?php 
    $theme_parallax = get_option('mt_theme_parallax');
    ?>
            <div class="parallax-container container-height"
                 <?php 
    if (get_theme_mod('mt_header_image_parallax_switch') == "1") {
        ?>
                     data-parallax="scroll"
                     data-bleed="10"
                     data-speed=".6"
                     data-image-src="<?php 
        echo get_theme_mod('mt_header_image');
        ?>
"
                 <?php 
    }
    ?>
  style="height:<?php 
    if (get_theme_mod('mt_header_image_height')) {
        echo get_theme_mod('mt_header_image_height');
    } else {
        echo "45vh";
/**
 * Returns a 'srcset' attribute.
 *
 * @since 2.1.0
 * @deprecated 3.0.0 Use 'wp_get_attachment_image_srcset()'
 *
 * @see wp_get_attachment_image_srcset()
 *
 * @param int          $id   Image attachment ID.
 * @param array|string $size Image size. Accepts any valid image size, or an array of width and height
 *                           values in pixels (in that order). Default 'medium'.
 * @return string|bool A full 'srcset' string or false.
 */
function tevkori_get_srcset_string($id, $size = 'medium')
{
    _deprecated_function(__FUNCTION__, '3.0.0', 'wp_get_attachment_image_srcset()');
    if (has_filter('tevkori_srcset_array')) {
        $srcset_value = tevkori_get_srcset($id, $size);
        return $srcset_value ? 'srcset="' . $srcset_value . '"' : false;
    } else {
        $srcset_value = wp_get_attachment_image_srcset($id, $size);
        return $srcset_value ? 'srcset="' . $srcset_value . '"' : false;
    }
}
Example #29
0
     * @param string $custom_header_sizes sizes attribute
     * for Custom Header. Default '(max-width: 709px) 85vw,
     * (max-width: 909px) 81vw, (max-width: 1362px) 88vw, 1200px'.
     */
    $custom_header_sizes = apply_filters('twentysixteen_custom_header_sizes', '(max-width: 709px) 85vw, (max-width: 909px) 81vw, (max-width: 1362px) 88vw, 1200px');
    ?>
				<div class="header-image">
					<a href="<?php 
    echo esc_url(home_url('/'));
    ?>
" rel="home">
						<img src="<?php 
    header_image();
    ?>
" srcset="<?php 
    echo esc_attr(wp_get_attachment_image_srcset(get_custom_header()->attachment_id));
    ?>
" sizes="<?php 
    echo esc_attr($custom_header_sizes);
    ?>
" width="<?php 
    echo esc_attr(get_custom_header()->width);
    ?>
" height="<?php 
    echo esc_attr(get_custom_header()->height);
    ?>
" alt="<?php 
    echo esc_attr(get_bloginfo('name', 'display'));
    ?>
">
					</a>
 /**
  * Show subcategory thumbnails.
  *
  * @param mixed $category
  * @subpackage	Loop
  */
 function woocommerce_subcategory_thumbnail($category)
 {
     $small_thumbnail_size = apply_filters('subcategory_archive_thumbnail_size', 'shop_catalog');
     $dimensions = wc_get_image_size($small_thumbnail_size);
     $thumbnail_id = get_woocommerce_term_meta($category->term_id, 'thumbnail_id', true);
     if ($thumbnail_id) {
         $image = wp_get_attachment_image_src($thumbnail_id, $small_thumbnail_size);
         $image = $image[0];
         $image_srcset = function_exists('wp_get_attachment_image_srcset') ? wp_get_attachment_image_srcset($thumbnail_id, $small_thumbnail_size) : false;
         $image_sizes = function_exists('wp_get_attachment_image_sizes') ? wp_get_attachment_image_sizes($thumbnail_id, $small_thumbnail_size) : false;
     } else {
         $image = wc_placeholder_img_src();
         $image_srcset = $image_sizes = false;
     }
     if ($image) {
         // Prevent esc_url from breaking spaces in urls for image embeds
         // Ref: https://core.trac.wordpress.org/ticket/23605
         $image = str_replace(' ', '%20', $image);
         // Add responsive image markup if available
         if ($image_srcset && $image_sizes) {
             echo '<img src="' . esc_url($image) . '" alt="' . esc_attr($category->name) . '" width="' . esc_attr($dimensions['width']) . '" height="' . esc_attr($dimensions['height']) . '" srcset="' . esc_attr($image_srcset) . '" sizes="' . esc_attr($image_sizes) . '" />';
         } else {
             echo '<img src="' . esc_url($image) . '" alt="' . esc_attr($category->name) . '" width="' . esc_attr($dimensions['width']) . '" height="' . esc_attr($dimensions['height']) . '" />';
         }
     }
 }