• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP wp_get_attachment_image_srcset函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中wp_get_attachment_image_srcset函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_get_attachment_image_srcset函数的具体用法?PHP wp_get_attachment_image_srcset怎么用?PHP wp_get_attachment_image_srcset使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了wp_get_attachment_image_srcset函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: get_html

 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;
 }
开发者ID:cibulka,项目名称:cibulka-wp-plugin-base,代码行数:29,代码来源:Image.php


示例2: get_thumbnail_source

 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;
 }
开发者ID:helsingborg-stad,项目名称:Modularity,代码行数:10,代码来源:Public.php


示例3: file_info

 /**
  * 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));
 }
开发者ID:kevin578,项目名称:mrteacherkevin,代码行数:22,代码来源:image.php


示例4: tevkori_filter_attachment_image_attributes

/**
 * 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;
}
开发者ID:mrakotomizao,项目名称:azuretest,代码行数:25,代码来源:wp-tevko-responsive-images.php


示例5: file_info

 /**
  * 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;
 }
开发者ID:rilwis,项目名称:meta-box,代码行数:26,代码来源:image.php


示例6: gannet_responsive_thumbnail

/**
 *
 */
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 
}
开发者ID:duanecilliers,项目名称:gannet,代码行数:25,代码来源:template-tags.php


示例7: test_wp_make_content_images_responsive_schemes

    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);
    }
开发者ID:barkinet,项目名称:wp-tevko-responsive-images,代码行数:28,代码来源:test-suite.php


示例8: siteorigin_widgets_get_attachment_image_src

}
?>

<?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)) {
    ?>
开发者ID:uwmadisoncals,项目名称:Cluster-Plugins,代码行数:31,代码来源:default.php


示例9: wc_get_product_attachment_props

/**
 * 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;
}
开发者ID:shivapoudel,项目名称:woocommerce,代码行数:33,代码来源:wc-product-functions.php


示例10: ubik_imagery_img

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);
}
开发者ID:synapticism,项目名称:ubik-imagery,代码行数:50,代码来源:ubik-imagery-core.php


示例11: get_post_meta

            //
            // 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;
        }
    }
}
开发者ID:FlorentinJakupi,项目名称:uxrennes-wp-theme,代码行数:31,代码来源:content-events.php


示例12: post_featured_image

 /**
  * 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);
 }
开发者ID:vfedushchin,项目名称:KingNews,代码行数:33,代码来源:class-tm-featured-posts-block-widget.php


示例13: file_info

 /**
  * 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));
 }
开发者ID:dsasko,项目名称:meta-box,代码行数:19,代码来源:image.php


示例14: get_post_meta

 // $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>";
 }
开发者ID:RRZE-Webteam,项目名称:FAU-Einrichtungen,代码行数:31,代码来源:page-start.php


示例15: test_wp_make_content_images_responsive

    /**
     * @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));
    }
开发者ID:rclilly,项目名称:wordpress-develop,代码行数:45,代码来源:media.php


示例16: get_image

 /**
  * 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;
 }
开发者ID:vfedushchin,项目名称:KingNews,代码行数:30,代码来源:class-tm-news-smart-box-widget.php


示例17: _carelib_image_get_srcset

/**
 * 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']);
}
开发者ID:wpsitecare,项目名称:carelib,代码行数:16,代码来源:image.php


示例18: widget


//.........这里部分代码省略.........
         }
     }
     $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") {
开发者ID:meowrika,项目名称:govintranet,代码行数:67,代码来源:ht_feature_news.php


示例19: while

    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 
开发者ID:adriamarcet,项目名称:therockery-theme,代码行数:31,代码来源:slider.php


示例20: create_image_tag

 /**
  * 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}/>";
     }
 }
开发者ID:bruno-barros,项目名称:w.eloquent.light,代码行数:30,代码来源:ad_type_image.php



注:本文中的wp_get_attachment_image_srcset函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP wp_get_attachment_image_url函数代码示例发布时间:2022-05-23
下一篇:
PHP wp_get_attachment_image_src函数代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap