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

PHP wp_get_attachment_thumb_file函数代码示例

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

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



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

示例1: image_downsize

function image_downsize($id, $size = 'medium')
{
    if (!wp_attachment_is_image($id)) {
        return false;
    }
    $img_url = wp_get_attachment_url($id);
    $meta = wp_get_attachment_metadata($id);
    $width = $height = 0;
    // plugins can use this to provide resize services
    if ($out = apply_filters('image_downsize', false, $id, $size)) {
        return $out;
    }
    // try for a new style intermediate size
    if ($intermediate = image_get_intermediate_size($id, $size)) {
        $img_url = str_replace(basename($img_url), $intermediate['file'], $img_url);
        $width = $intermediate['width'];
        $height = $intermediate['height'];
    } elseif ($size == 'thumbnail') {
        // fall back to the old thumbnail
        if (($thumb_file = wp_get_attachment_thumb_file($id)) && ($info = getimagesize($thumb_file))) {
            $img_url = str_replace(basename($img_url), basename($thumb_file), $img_url);
            $width = $info[0];
            $height = $info[1];
        }
    }
    if (!$width && !$height && isset($meta['width'], $meta['height'])) {
        // any other type: use the real image and constrain it
        list($width, $height) = image_constrain_size_for_editor($meta['width'], $meta['height'], $size);
    }
    if ($img_url) {
        return array($img_url, $width, $height);
    }
    return false;
}
开发者ID:nurpax,项目名称:saastafi,代码行数:34,代码来源:media.php


示例2: downsize

 function downsize($out, $id, $size)
 {
     $img_url = wp_get_attachment_url($id);
     $img_path = get_attached_file($id);
     $meta = wp_get_attachment_metadata($id);
     $width = $height = 0;
     $is_intermediate = false;
     $img_url_basename = wp_basename($img_url);
     $img_path_basename = wp_basename($img_path);
     // extract filter from size request
     if (!is_string($size)) {
         return $out;
     }
     $size_bits = explode(':', $size);
     $filter = isset($size_bits[1]) ? $size_bits[1] : false;
     $size = isset($size_bits[0]) ? $size_bits[0] : false;
     // start the reactor
     if ($filter) {
         // try for a new style intermediate size
         if ($intermediate = image_get_intermediate_size($id, $size)) {
             $img_url = str_replace($img_url_basename, $intermediate['file'], $img_url);
             $img_path = str_replace($img_path_basename, $intermediate['file'], $img_path);
             $width = $intermediate['width'];
             $height = $intermediate['height'];
             $is_intermediate = true;
         } elseif ($size == 'thumbnail') {
             // fall back to the old thumbnail
             if (($thumb_file = wp_get_attachment_thumb_file($id)) && ($info = getimagesize($thumb_file))) {
                 $img_url = str_replace($img_url_basename, wp_basename($thumb_file), $img_url);
                 $img_path = str_replace($img_path_basename, wp_basename($thumb_file), $img_path);
                 $width = $info[0];
                 $height = $info[1];
                 $is_intermediate = true;
             }
         }
         if (!$width && !$height && isset($meta['width'], $meta['height'])) {
             // any other type: use the real image
             $width = $meta['width'];
             $height = $meta['height'];
         }
         if ($img_url && $img_path) {
             $input = $img_path;
             $output = $this->filtered_url($input, $filter);
             // generate filtered thumb
             if (!file_exists($output)) {
                 $this->filter($filter, $input, $output);
             }
             // point to our new file
             $img_url = $this->filtered_url($img_url, $filter);
             // we have the actual image size, but might need to further constrain it if content_width is narrower
             list($width, $height) = image_constrain_size_for_editor($width, $height, $size);
             return array($img_url, $width, $height, $is_intermediate);
         }
         // don't continue the downsize funtion
         return true;
     }
     return $out;
 }
开发者ID:netconstructor,项目名称:wp-instagraph,代码行数:58,代码来源:wp-instagraph.php


示例3: __wp_supercustom_cms_image_downsize

/**
 * Uses WordPress filter for image_downsize, kill wp-image-dimension
 * code by Andrew Rickmann
 * http://www.wp-fun.co.uk/
 * @param $value, $id, $size
 */
function __wp_supercustom_cms_image_downsize($value = FALSE, $id = 0, $size = 'medium')
{
    if (!wp_attachment_is_image($id)) {
        return FALSE;
    }
    $img_url = wp_get_attachment_url($id);
    // Mimic functionality in image_downsize function in wp-includes/media.php
    if ($intermediate = image_get_intermediate_size($id, $size)) {
        $img_url = str_replace(basename($img_url), $intermediate['file'], $img_url);
    } elseif ($size == 'thumbnail') {
        // fall back to the old thumbnail
        if ($thumb_file = wp_get_attachment_thumb_file() && ($info = getimagesize($thumb_file))) {
            $img_url = str_replace(basename($img_url), basename($thumb_file), $img_url);
        }
    }
    if ($img_url) {
        return array($img_url, 0, 0);
    }
    return FALSE;
}
开发者ID:nishant368,项目名称:newlifeoffice-new,代码行数:26,代码来源:__wp_supercustom_cms_functions.php


示例4: wp_get_attachment_thumb_url

/**
 * Retrieve URL for an attachment thumbnail.
 *
 * @since 2.1.0
 *
 * @param int $post_id Attachment ID
 * @return string|bool False on failure. Thumbnail URL on success.
 */
function wp_get_attachment_thumb_url($post_id = 0)
{
    $post_id = (int) $post_id;
    if (!($post =& get_post($post_id))) {
        return false;
    }
    if (!($url = wp_get_attachment_url($post->ID))) {
        return false;
    }
    $sized = image_downsize($post_id, 'thumbnail');
    if ($sized) {
        return $sized[0];
    }
    if (!($thumb = wp_get_attachment_thumb_file($post->ID))) {
        return false;
    }
    $url = str_replace(basename($url), basename($thumb), $url);
    return apply_filters('wp_get_attachment_thumb_url', $url, $post->ID);
}
开发者ID:BGCX261,项目名称:zombie-craft-svn-to-git,代码行数:27,代码来源:post.php


示例5: wp_get_attachment_thumb_url

/**
 * Retrieve URL for an attachment thumbnail.
 *
 * @since 2.1.0
 *
 * @param int $post_id Optional. Attachment ID. Default 0.
 * @return string|false False on failure. Thumbnail URL on success.
 */
function wp_get_attachment_thumb_url($post_id = 0)
{
    $post_id = (int) $post_id;
    if (!($post = get_post($post_id))) {
        return false;
    }
    if (!($url = wp_get_attachment_url($post->ID))) {
        return false;
    }
    $sized = image_downsize($post_id, 'thumbnail');
    if ($sized) {
        return $sized[0];
    }
    if (!($thumb = wp_get_attachment_thumb_file($post->ID))) {
        return false;
    }
    $url = str_replace(basename($url), basename($thumb), $url);
    /**
     * Filter the attachment thumbnail URL.
     *
     * @since 2.1.0
     *
     * @param string $url     URL for the attachment thumbnail.
     * @param int    $post_id Attachment ID.
     */
    return apply_filters('wp_get_attachment_thumb_url', $url, $post->ID);
}
开发者ID:SayenkoDesign,项目名称:ividf,代码行数:35,代码来源:post.php


示例6: image_downsize

/**
 * Scale an image to fit a particular size (such as 'thumb' or 'medium').
 *
 * Array with image url, width, height, and whether is intermediate size, in
 * that order is returned on success is returned. $is_intermediate is true if
 * $url is a resized image, false if it is the original.
 *
 * The URL might be the original image, or it might be a resized version. This
 * function won't create a new resized copy, it will just return an already
 * resized one if it exists.
 *
 * A plugin may use the 'image_downsize' filter to hook into and offer image
 * resizing services for images. The hook must return an array with the same
 * elements that are returned in the function. The first element being the URL
 * to the new image that was resized.
 *
 * @since 2.5.0
 *
 * @param int          $id   Attachment ID for image.
 * @param array|string $size Optional. Image size to scale to. Accepts any valid image size,
 *                           or an array of width and height values in pixels (in that order).
 *                           Default 'medium'.
 * @return false|array Array containing the image URL, width, height, and boolean for whether
 *                     the image is an intermediate size. False on failure.
 */
function image_downsize($id, $size = 'medium')
{
    if (!wp_attachment_is_image($id)) {
        return false;
    }
    /**
     * Filter whether to preempt the output of image_downsize().
     *
     * Passing a truthy value to the filter will effectively short-circuit
     * down-sizing the image, returning that value as output instead.
     *
     * @since 2.5.0
     *
     * @param bool         $downsize Whether to short-circuit the image downsize. Default false.
     * @param int          $id       Attachment ID for image.
     * @param array|string $size     Size of image. Image size or array of width and height values (in that order).
     *                               Default 'medium'.
     */
    if ($out = apply_filters('image_downsize', false, $id, $size)) {
        return $out;
    }
    $img_url = wp_get_attachment_url($id);
    $meta = wp_get_attachment_metadata($id);
    $width = $height = 0;
    $is_intermediate = false;
    $img_url_basename = wp_basename($img_url);
    // try for a new style intermediate size
    if ($intermediate = image_get_intermediate_size($id, $size)) {
        $img_url = str_replace($img_url_basename, $intermediate['file'], $img_url);
        $width = $intermediate['width'];
        $height = $intermediate['height'];
        $is_intermediate = true;
    } elseif ($size == 'thumbnail') {
        // fall back to the old thumbnail
        if (($thumb_file = wp_get_attachment_thumb_file($id)) && ($info = getimagesize($thumb_file))) {
            $img_url = str_replace($img_url_basename, wp_basename($thumb_file), $img_url);
            $width = $info[0];
            $height = $info[1];
            $is_intermediate = true;
        }
    }
    if (!$width && !$height && isset($meta['width'], $meta['height'])) {
        // any other type: use the real image
        $width = $meta['width'];
        $height = $meta['height'];
    }
    if ($img_url) {
        // we have the actual image size, but might need to further constrain it if content_width is narrower
        list($width, $height) = image_constrain_size_for_editor($width, $height, $size);
        return array($img_url, $width, $height, $is_intermediate);
    }
    return false;
}
开发者ID:nakamuraagatha,项目名称:reseptest,代码行数:78,代码来源:media.php


示例7: convert_get_attachment_to_cloudinary_pull_request

 /**
  * Filter all thumbnails and image attachments typically used in template parts, archive loops, and widgets
  */
 static function convert_get_attachment_to_cloudinary_pull_request($override, $id, $size)
 {
     $account = static::get_option_value('cloud_name');
     //if no account is set, do not continue
     if (empty($account)) {
         return false;
     }
     //prepare values for string replacements
     $img_url = wp_get_attachment_url($id);
     $meta = wp_get_attachment_metadata($id);
     $width = $height = 0;
     $is_intermediate = false;
     $img_url_basename = wp_basename($img_url);
     $cdn_fetch_prefix = static::get_cdn_prefix($account);
     // try for a new style intermediate size
     if ($intermediate = image_get_intermediate_size($id, $size)) {
         $width = $intermediate['width'];
         $height = $intermediate['height'];
         $original = image_get_intermediate_size($id, 'full');
         $is_intermediate = true;
     } elseif ($size == 'thumbnail') {
         if (($thumb_file = wp_get_attachment_thumb_file($id)) && ($info = getimagesize($thumb_file))) {
             $width = $info[0];
             $height = $info[1];
             $is_intermediate = true;
         }
     }
     //make sure we have height and width values
     if (!$width && !$height && isset($meta['width'], $meta['height'])) {
         // any other type: use the real image
         $width = $meta['width'];
         $height = $meta['height'];
     }
     //if image found then modify it with cloudinary optimimized replacement
     if ($img_url) {
         $site_url = get_bloginfo('url');
         // get_bloginfo( 'url' ) is called a few time, it should be move to a property of this class, i.e. $this->blogurl, or something
         $site_url_no_protocal = preg_replace('/http[s]?:\\/\\//', '', $site_url);
         // we have the actual image size, but might need to further constrain it if content_width is narrower
         list($width, $height) = image_constrain_size_for_editor($width, $height, $size);
         $cdn_fetch_options = static::get_cdn_options($height, $width);
         //strip protocal from image URL
         $cdn_img_url = preg_replace('/(http:|https:)?\\/\\/(.*)/i', '$1' . $cdn_fetch_prefix . $cdn_fetch_options . "/\$2", $img_url);
         // do you need the double quotes on /$2 here or would single quotes work?
         return array($cdn_img_url, $width, $height, $is_intermediate);
     }
     //if for some reason $img_url fails, disable filter by returning false
     return false;
 }
开发者ID:WordPress-Phoenix,项目名称:wordpress-cloudinary-config-free-cdn-images,代码行数:52,代码来源:sm-cloudinary-config-free-cdn-images.php


示例8: wp_get_attachment_thumb_url

function wp_get_attachment_thumb_url( $post_id = 0 ) {
	$post_id = (int) $post_id;
	if ( !$post =& get_post( $post_id ) )
		return false;
	if ( !$url = wp_get_attachment_url( $post->ID ) )
		return false;

	if ( !$thumb = wp_get_attachment_thumb_file( $post->ID ) )
		return false;

	$url = str_replace(basename($url), basename($thumb), $url);

	return apply_filters( 'wp_get_attachment_thumb_url', $url, $post->ID );
}
开发者ID:staylor,项目名称:develop.svn.wordpress.org,代码行数:14,代码来源:post.php


示例9: get_attachment_icon_src

function get_attachment_icon_src( $id = 0, $fullsize = false ) {
	$id = (int) $id;
	if ( !$post = & get_post($id) )
		return false;

	$imagedata = wp_get_attachment_metadata( $post->ID );

	$file = get_attached_file( $post->ID );

	if ( !$fullsize && $thumbfile = wp_get_attachment_thumb_file( $post->ID ) ) {
		// We have a thumbnail desired, specified and existing

		$src = wp_get_attachment_thumb_url( $post->ID );
		$src_file = $thumbfile;
		$class = 'attachmentthumb';
	} elseif ( wp_attachment_is_image( $post->ID ) ) {
		// We have an image without a thumbnail

		$src = wp_get_attachment_url( $post->ID );
		$src_file = & $file;
		$class = 'attachmentimage';
	} elseif ( $src = wp_mime_type_icon( $post->ID ) ) {
		// No thumb, no image. We'll look for a mime-related icon instead.

		$icon_dir = apply_filters( 'icon_dir', get_template_directory() . '/images' );
		$src_file = $icon_dir . '/' . basename($src);
	}

	if ( !isset($src) || !$src )
		return false;

	return array($src, $src_file);
}
开发者ID:staylor,项目名称:develop.svn.wordpress.org,代码行数:33,代码来源:post-template.php


示例10: h2only_image_downsize

function h2only_image_downsize($value = false, $id, $size)
{
    if (!wp_attachment_is_image($id)) {
        return false;
    }
    $img_url = wp_get_attachment_url($id);
    $is_intermediate = false;
    $img_url_basename = wp_basename($img_url);
    // try for a new style intermediate size
    if ($intermediate = image_get_intermediate_size($id, $size)) {
        $img_url = str_replace($img_url_basename, $intermediate['file'], $img_url);
        $is_intermediate = true;
    } elseif ($size == 'thumbnail') {
        // Fall back to the old thumbnail
        if (($thumb_file = wp_get_attachment_thumb_file($id)) && ($info = getimagesize($thumb_file))) {
            $img_url = str_replace($img_url_basename, wp_basename($thumb_file), $img_url);
            $is_intermediate = true;
        }
    }
    // We have the actual image size, but might need to further constrain it if content_width is narrower
    if ($img_url) {
        return array($img_url, 0, 0, $is_intermediate);
    }
    return false;
}
开发者ID:parsonsc,项目名称:dofe,代码行数:25,代码来源:h2only.php


示例11: thumb

/**
 * Get a thumbnail for an attachment, allowing us to override wp_options.
 *
 * @param int $id ID of attachment
 * @param int $max_w Maximum width (wp_option setting by default)
 * @param int $max_h Maximum height (wp_option setting by default)
 * @param bool $crop Should we crop rather than scale? (wp_option setting by default)
 * @return string URL of thumbnail, or false
 */
function thumb($id, $max_w = null, $max_h = null, $crop = null)
{
    if ($max_w === null) {
        $max_w = get_option('thumbnail_size_w');
    }
    if ($max_h === null) {
        $max_h = get_option('thumbnail_size_h');
    }
    if ($crop === null) {
        $crop = get_option('thumbnail_crop');
    }
    return str_replace(basename(wp_get_attachment_thumb_url($id)), basename(image_resize(wp_get_attachment_thumb_file($id), $max_w, $max_h, $crop)), wp_get_attachment_thumb_url($id));
}
开发者ID:randomblast,项目名称:themebase,代码行数:22,代码来源:image.php


示例12: hello_img

function hello_img($value, $id, $size = 'medium')
{
    $img_url = wp_get_attachment_url($id);
    $meta = wp_get_attachment_metadata($id);
    $width = $height = 0;
    $is_intermediate = false;
    $img_url_basename = wp_basename($img_url);
    // try for a new style intermediate size
    if ($intermediate = image_get_intermediate_size($id, $size)) {
        $img_url = str_replace($img_url_basename, $intermediate['file'], $img_url);
        $width = $intermediate['width'];
        $height = $intermediate['height'];
        $is_intermediate = true;
    } elseif ($size == 'thumbnail') {
        // fall back to the old thumbnail
        if (($thumb_file = wp_get_attachment_thumb_file($id)) && ($info = getimagesize($thumb_file))) {
            $img_url = str_replace($img_url_basename, wp_basename($thumb_file), $img_url);
            $width = $info[0];
            $height = $info[1];
            $is_intermediate = true;
        }
    }
    if (!$width && !$height && isset($meta['width'], $meta['height'])) {
        // any other type: use the real image
        $width = $meta['width'];
        $height = $meta['height'];
    }
    if ($img_url) {
        $header_response = get_headers($img_url, 1);
        if (strpos($header_response[0], "404") == false) {
            // we have the actual image size, but might need to further constrain it if content_width is narrower
            list($width, $height) = image_constrain_size_for_editor($width, $height, $size);
            return array($img_url, $width, $height, $is_intermediate);
        } else {
            $html = get_template_directory_uri() . '/assets/img/placeholder/' . $size . '.png';
            return array($html, $width, $height, $is_intermediate);
        }
    }
    return false;
}
开发者ID:pqzada,项目名称:avispate,代码行数:40,代码来源:utils.php



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
PHP wp_get_attachment_thumb_url函数代码示例发布时间:2022-05-23
下一篇:
PHP wp_get_attachment_metadata函数代码示例发布时间: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