当前位置: 首页>>代码示例>>PHP>>正文


PHP Jetpack_PostImages::fit_image_url方法代码示例

本文整理汇总了PHP中Jetpack_PostImages::fit_image_url方法的典型用法代码示例。如果您正苦于以下问题:PHP Jetpack_PostImages::fit_image_url方法的具体用法?PHP Jetpack_PostImages::fit_image_url怎么用?PHP Jetpack_PostImages::fit_image_url使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Jetpack_PostImages的用法示例。


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

示例1: _generate_related_post_image_params

 /**
  * Generates the thumbnail image to be used for the post. Uses the
  * image as returned by Jetpack_PostImages::get_image()
  *
  * @param int $post_id
  * @uses self::get_options, apply_filters, Jetpack_PostImages::get_image, Jetpack_PostImages::fit_image_url
  * @return string
  */
 protected function _generate_related_post_image_params($post_id)
 {
     $options = $this->get_options();
     $image_params = array('src' => '', 'width' => 0, 'height' => 0);
     if (!$options['show_thumbnails']) {
         return $image_params;
     }
     $thumbnail_size = apply_filters('jetpack_relatedposts_filter_thumbnail_size', array('width' => 350, 'height' => 200));
     if (!is_array($thumbnail_size)) {
         $thumbnail_size = array('width' => (int) $thumbnail_size, 'height' => (int) $thumbnail_size);
     }
     // Try to get post image
     if (class_exists('Jetpack_PostImages')) {
         $img_url = '';
         $post_image = Jetpack_PostImages::get_image($post_id, $thumbnail_size);
         if (is_array($post_image)) {
             $img_url = $post_image['src'];
         } elseif (class_exists('Jetpack_Media_Summary')) {
             $media = Jetpack_Media_Summary::get($post_id);
             if (is_array($media) && !empty($media['image'])) {
                 $img_url = $media['image'];
             }
         }
         if (!empty($img_url)) {
             $image_params['width'] = $thumbnail_size['width'];
             $image_params['height'] = $thumbnail_size['height'];
             $image_params['src'] = Jetpack_PostImages::fit_image_url($img_url, $thumbnail_size['width'], $thumbnail_size['height']);
         }
     }
     return $image_params;
 }
开发者ID:moushegh,项目名称:blog-source-configs,代码行数:39,代码来源:jetpack-related-posts.php

示例2: boardwalk_get_image

/**
 * Get one image from a specified post in the following order:
 * Featured Image, first attached image, first image from the_content HTML
 *
 * @param int $id, The post ID to check
 * @param string        $size   The image size to return, defaults to 'featured-home-big'.
 * @param string|array  $attr   Optional. Query string or array of attributes.
 * @return string       $thumb  Thumbnail image with markup.
 */
function boardwalk_get_image($post_id = null, $size = 'post-thumbnail', $attr = '')
{
    $post_id = null === $post_id ? get_the_ID() : $post_id;
    if ('' != get_the_post_thumbnail($post_id)) {
        return get_the_post_thumbnail($post_id, $size, $attr);
    }
    $attached_images = get_attached_media('image');
    if (!empty($attached_images)) {
        $first_attached_image = array_shift($attached_images);
        return wp_get_attachment_image($first_attached_image->ID, $size, false, $attr);
    }
    if (class_exists('Jetpack_PostImages')) {
        global $_wp_additional_image_sizes;
        $args = array('from_thumbnail' => false, 'from_slideshow' => true, 'from_gallery' => true, 'from_attachment' => false);
        $image = Jetpack_PostImages::get_image($post_id, $args);
        if (!empty($image)) {
            $image['width'] = '';
            $image['height'] = '';
            if (array_key_exists($size, $_wp_additional_image_sizes)) {
                $image['width'] = $_wp_additional_image_sizes[$size]['width'];
                $image['height'] = $_wp_additional_image_sizes[$size]['height'];
            }
            $image_src = Jetpack_PostImages::fit_image_url($image['src'], $image['width'], $image['height']);
            return '<img src="' . esc_url($image_src) . '" title="' . esc_attr(strip_tags(get_the_title())) . '" class="attachment-' . esc_attr($size) . ' wp-post-image" />';
        }
    }
    return false;
}
开发者ID:kanei,项目名称:vantuch.cz,代码行数:37,代码来源:extras.php


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