本文整理汇总了PHP中wc_get_image_size函数的典型用法代码示例。如果您正苦于以下问题:PHP wc_get_image_size函数的具体用法?PHP wc_get_image_size怎么用?PHP wc_get_image_size使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wc_get_image_size函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: woocommerce_get_product_thumbnail
function woocommerce_get_product_thumbnail($size = 'shop_catalog', $placeholder_width = 0, $placeholder_height = 0)
{
global $post, $woocommerce, $data;
if (!$placeholder_width) {
if (function_exists('wc_get_image_size')) {
$placeholder_width = wc_get_image_size('shop_catalog_image_width');
} else {
$placeholder_width = $woocommerce->get_image_size('shop_catalog_image_width');
}
}
if (!$placeholder_height) {
if (function_exists('wc_get_image_size')) {
$placeholder_height = wc_get_image_size('shop_catalog_image_height');
} else {
$placeholder_height = $woocommerce->get_image_size('shop_catalog_image_height');
}
}
$output = '<div class="image">';
if (has_post_thumbnail()) {
$width = '150';
$height = '130';
if (!empty($data['woo_cat_image_size'])) {
$width = $data['woo_cat_image_size']['width'];
$height = $data['woo_cat_image_size']['height'];
}
$image = vt_resize(get_post_thumbnail_id($post->ID), '', $width, $height, true);
$output .= '<a href="' . get_permalink() . '"><img src="' . $image['url'] . '" alt=""></a>';
} else {
$output .= '<img src="' . woocommerce_placeholder_img_src() . '" alt="Placeholder" width="' . $placeholder_width . '" height="' . $placeholder_height . '" />';
}
$output .= '</div>';
return $output;
}
示例2: yit_get_image_size
/**
* Get default image size
*
* @param array $size current size
*
* @return array
* @author Lorenzo Giuffrida
* @since 1.0.0
*/
function yit_get_image_size($size)
{
if (function_exists('wc_get_image_size')) {
return wc_get_image_size($size);
} else {
global $woocommerce;
return $woocommerce->get_image_size($size);
}
}
示例3: yit_shop_thumbnail_w
/**
* Return the shop_thumbnail image width
*
* @return integer
* @since 1.0.0
*/
function yit_shop_thumbnail_w()
{
global $woocommerce;
if (function_exists('wc_get_image_size')) {
$size = wc_get_image_size('shop_thumbnail');
} else {
$size = $woocommerce->get_image_size('shop_thumbnail');
}
return $size['width'];
}
示例4: woops_get_product_thumbnail
public static function woops_get_product_thumbnail($post_id, $size = 'shop_catalog', $placeholder_width = 0, $placeholder_height = 0)
{
global $woocommerce;
$woocommerce_db_version = get_option('woocommerce_db_version', null);
$shop_catalog = version_compare($woocommerce_db_version, '2.1', '<') ? $woocommerce->get_image_size('shop_catalog') : wc_get_image_size('shop_catalog');
if (is_array($shop_catalog) && isset($shop_catalog['width']) && $placeholder_width == 0) {
$placeholder_width = $shop_catalog['width'];
}
if (is_array($shop_catalog) && isset($shop_catalog['height']) && $placeholder_height == 0) {
$placeholder_height = $shop_catalog['height'];
}
if (has_post_thumbnail($post_id)) {
return get_the_post_thumbnail($post_id, $size);
}
$mediumSRC = '';
if (trim($mediumSRC == '')) {
$args = array('post_parent' => $post_id, 'numberposts' => 1, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'DESC', 'orderby' => 'ID', 'post_status' => null);
$attachments = get_posts($args);
if ($attachments) {
foreach ($attachments as $attachment) {
$mediumSRC = wp_get_attachment_image($attachment->ID, $size, true);
break;
}
}
}
if (trim($mediumSRC == '')) {
// Load the product
$product = get_post($post_id);
// Get ID of parent product if one exists
if (!empty($product->post_parent)) {
$post_id = $product->post_parent;
}
if (has_post_thumbnail($post_id)) {
return get_the_post_thumbnail($post_id, $size);
}
if (trim($mediumSRC == '')) {
$args = array('post_parent' => $post_id, 'numberposts' => 1, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'DESC', 'orderby' => 'ID', 'post_status' => null);
$attachments = get_posts($args);
if ($attachments) {
foreach ($attachments as $attachment) {
$mediumSRC = wp_get_attachment_image($attachment->ID, $size, true);
break;
}
}
}
}
if (trim($mediumSRC != '')) {
return $mediumSRC;
} else {
return '<img src="' . (version_compare($woocommerce_db_version, '2.1', '<') ? woocommerce_placeholder_img_src() : wc_placeholder_img_src()) . '" alt="Placeholder" width="' . $placeholder_width . '" height="' . $placeholder_height . '" />';
}
}
示例5: display_field
public function display_field($element = array(), $args = array())
{
$this->_columns++;
$this->grid_break = "";
$default_value = isset($element['default_value']) ? is_array($element['default_value']) ? in_array((string) $this->_default_value_counter, $element['default_value']) : false : false;
if ((double) $this->_columns > (double) $this->items_per_row && $this->items_per_row > 0) {
$this->grid_break = " cpf_clear";
$this->_columns = 1;
}
$hexclass = "";
$li_class = "";
$search_for_color = $args['label'];
if (isset($element['color'])) {
$search_for_color = $element['color'];
}
if (preg_match('/#([a-f]|[A-F]|[0-9]){3}(([a-f]|[A-F]|[0-9]){3})?\\b/', $search_for_color)) {
$size = 'shop_thumbnail';
$dimensions = wc_get_image_size($size);
$tmhexcolor = 'tmhexcolor_' . $args['element_counter'] . "_" . $args['field_counter'] . "_" . $args['tabindex'] . $args['form_prefix'];
$hexclass = $tmhexcolor;
$this->css_string = "." . $tmhexcolor . " + label .tmhexcolorimage{background-color:" . $search_for_color . " !important;}";
if (!empty($element['item_width'])) {
if (is_numeric($element['item_width'])) {
$element['item_width'] .= "px";
}
$this->css_string .= "." . $tmhexcolor . " + label .tmhexcolorimage{display: inline-block !important;width:" . $element['item_width'] . " !important;min-width:" . $element['item_width'] . " !important;max-width:" . $element['item_width'] . " !important;}";
}
if (!empty($element['item_height'])) {
if (is_numeric($element['item_height'])) {
$element['item_height'] .= "px";
}
$this->css_string .= "." . $tmhexcolor . " + label .tmhexcolorimage{display: inline-block !important;height:" . $element['item_height'] . " !important;min-height:" . $element['item_height'] . " !important;max-height:" . $element['item_height'] . " !important;}";
}
if (!empty($element['item_width']) || !empty($element['item_height'])) {
$this->css_string .= ".tmhexcolorimage-li.tm-li-unique-" . $args['element_counter'] . "-" . $args['field_counter'] . "-" . $args['tabindex'] . $args['form_prefix'] . "{display: inline-block;}";
$li_class .= "tmhexcolorimage-li tm-li-unique-" . $args['element_counter'] . "-" . $args['field_counter'] . "-" . $args['tabindex'] . $args['form_prefix'];
} else {
$li_class .= "tmhexcolorimage-li-nowh";
}
$this->css_string = str_replace(array("\r", "\n"), "", $this->css_string);
TM_EPO()->inline_styles = TM_EPO()->inline_styles . $this->css_string;
}
$display = array('li_class' => $li_class, 'class' => !empty($element['class']) ? $element['class'] . ' ' . $hexclass : "" . $hexclass, 'label' => wptexturize(apply_filters('woocommerce_tm_epo_option_name', $args['label'])), 'value' => esc_attr($args['value']), 'id' => 'tmcp_choice_' . $args['element_counter'] . "_" . $args['field_counter'] . "_" . $args['tabindex'] . $args['form_prefix'], 'textbeforeprice' => isset($element['text_before_price']) ? $element['text_before_price'] : "", 'textafterprice' => isset($element['text_after_price']) ? $element['text_after_price'] : "", 'hide_amount' => isset($element['hide_amount']) ? " " . $element['hide_amount'] : "", 'use_images' => $element['use_images'], 'use_lightbox' => isset($element['use_lightbox']) ? $element['use_lightbox'] : "", 'use_url' => $element['use_url'], 'grid_break' => $this->grid_break, 'items_per_row' => $this->items_per_row, 'percent' => $this->_percent, 'image' => isset($element['images'][$args['field_counter']]) ? $element['images'][$args['field_counter']] : "", 'imagep' => isset($element['imagesp'][$args['field_counter']]) ? $element['imagesp'][$args['field_counter']] : "", 'url' => isset($element['url'][$args['field_counter']]) ? $element['url'][$args['field_counter']] : "", 'limit' => empty($element['limit']) ? "" : $element['limit'], 'exactlimit' => empty($element['exactlimit']) ? "" : $element['exactlimit'], 'minimumlimit' => empty($element['minimumlimit']) ? "" : $element['minimumlimit'], 'swatchmode' => empty($element['swatchmode']) ? "" : $element['swatchmode'], 'tm_epo_no_lazy_load' => TM_EPO()->tm_epo_no_lazy_load, 'changes_product_image' => empty($element['changes_product_image']) ? "" : $element['changes_product_image'], 'default_value' => $default_value, 'quantity' => isset($element['quantity']) ? $element['quantity'] : "");
if (isset($element['color'])) {
$display["color"] = $element['color'];
}
$this->_default_value_counter++;
return $display;
}
示例6: woocommerce_get_product_thumbnail
function woocommerce_get_product_thumbnail($size = 'shop_catalog', $placeholder_width = 0, $placeholder_height = 0)
{
global $post, $woocommerce;
if (!$placeholder_width) {
$placeholder_width = wc_get_image_size('shop_catalog_image_width');
}
if (!$placeholder_height) {
$placeholder_height = wc_get_image_size('shop_catalog_image_height');
}
$output = '<a href="' . get_permalink() . '">';
if (has_post_thumbnail()) {
$output .= get_the_post_thumbnail($post->ID, $size);
} else {
$output .= '<img src="' . woocommerce_placeholder_img_src() . '" alt="Placeholder" width="' . $placeholder_width . '" height="' . $placeholder_height . '" />';
}
$output .= '</a>';
return $output;
}
示例7: woocommerce_subcategory_thumbnail
function woocommerce_subcategory_thumbnail($category)
{
$small_thumbnail_size = apply_filters('single_product_small_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];
} else {
$image = wc_placeholder_img_src();
}
if ($image) {
// Prevent esc_url from breaking spaces in urls for image embeds
// Ref: http://core.trac.wordpress.org/ticket/23605
$image = str_replace(' ', '%20', $image);
echo '<img src="' . esc_url($image) . '" alt="' . esc_attr($category->name) . '"/>';
}
}
示例8: yit_shop_featured_c
function yit_shop_featured_c()
{
$size = wc_get_image_size('shop_featured');
return $size['crop'];
}
示例9: woocommerce_subcategory_thumbnail
function woocommerce_subcategory_thumbnail($category)
{
$small_thumbnail_size = apply_filters('single_product_small_thumbnail_size', 'product_small_thumbnail');
$thumbnail_size = apply_filters('single_product_small_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_small = wp_get_attachment_image_src($thumbnail_id, $small_thumbnail_size);
$image_small = $image_small[0];
$image = wp_get_attachment_image_src($thumbnail_id, $thumbnail_size);
$image = $image[0];
} else {
$image = $image_small = wc_placeholder_img_src();
}
if ($image_small) {
echo '<img data-src="' . esc_url($image) . '" class="lazyOwl" src="' . esc_url($image_small) . '" alt="' . esc_attr($category->name) . '" width="' . esc_attr($dimensions['width']) . '" height="' . esc_url($dimensions['height']) . '" />';
}
}
示例10: avada_dynamic_css_array
//.........这里部分代码省略.........
$css['global']['.woocommerce-tabs > .tabs']['border-bottom'] = '1px solid #dddddd';
$css['global']['.woocommerce-tabs > .tabs li']['float'] = 'left';
$css['global']['.woocommerce-tabs > .tabs li a']['border'] = '1px solid transparent !important';
$css['global']['.woocommerce-tabs > .tabs li a']['padding'] = '10px 20px';
$css['global']['.woocommerce-tabs > .tabs .active']['border'] = '1px solid #dddddd';
$css['global']['.woocommerce-tabs > .tabs .active']['border-bottom'] = 'none';
$css['global']['.woocommerce-tabs > .tabs .active']['min-height'] = '40px';
$css['global']['.woocommerce-tabs > .tabs .active']['margin-bottom'] = '-1px';
$css['global']['.woocommerce-tabs > .tabs .active:hover a']['cursor'] = 'default';
$css['global']['.woocommerce-tabs .entry-content']['float'] = 'left';
$css['global']['.woocommerce-tabs .entry-content']['margin'] = '0px';
$css['global']['.woocommerce-tabs .entry-content']['width'] = '100%';
$css['global']['.woocommerce-tabs .entry-content']['border-top'] = 'none';
}
if ('0' != Avada_Color::get_alpha_from_rgba(Avada()->settings->get('timeline_bg_color'))) {
$css['global']['.products .product-list-view']['padding-left'] = '20px';
$css['global']['.products .product-list-view']['padding-right'] = '20px';
}
$elements = array('.fusion-item-in-cart .fusion-rollover-content .fusion-rollover-title', '.fusion-item-in-cart .fusion-rollover-content .fusion-rollover-categories', '.fusion-item-in-cart .fusion-rollover-content .price', '.fusion-carousel-title-below-image .fusion-item-in-cart .fusion-rollover-content .fusion-product-buttons', '.products .product .fusion-item-in-cart .fusion-rollover-content .fusion-product-buttons');
$css['global'][avada_implode($elements)]['display'] = 'none';
if ('clean' == Avada()->settings->get('woocommerce_product_box_design')) {
$css['global']['.fusion-woo-product-design-clean .products .fusion-rollover .star-rating span:before, .fusion-woo-product-design-clean .products .fusion-rollover .star-rating:before']['color'] = Avada_Sanitize::color(Avada()->settings->get('image_rollover_icon_color'));
$css['global']['.fusion-woo-product-design-clean .products .fusion-rollover-content .fusion-product-buttons, .fusion-woo-slider .fusion-product-buttons']['color'] = Avada_Sanitize::color(Avada()->settings->get('image_rollover_text_color'));
$css['global']['.fusion-woo-product-design-clean .products .fusion-rollover-content .fusion-product-buttons a, .fusion-woo-slider .fusion-product-buttons a']['color'] = Avada_Sanitize::color(Avada()->settings->get('image_rollover_text_color'));
$css['global']['.fusion-woo-product-design-clean .products .fusion-rollover-content .fusion-product-buttons a, .fusion-woo-slider .fusion-product-buttons a']['letter-spacing'] = '1px';
$css['global']['.fusion-woo-product-design-clean .products .fusion-rollover-content .fusion-rollover-linebreak, .fusion-woo-slider .fusion-product-buttons .fusion-rollover-linebreak']['color'] = Avada_Sanitize::color(Avada()->settings->get('image_rollover_text_color'));
}
// Make the single product page layout reflect the single image size in Woo settings
if (is_product()) {
$post_image = get_the_post_thumbnail(get_the_ID(), apply_filters('single_product_large_thumbnail_size', 'shop_single'));
if ($post_image) {
preg_match('@width="([^"]+)"@', $post_image, $match);
if ('500' != $match[1]) {
$shop_single_image_size = wc_get_image_size('shop_single');
$css['global']['.product .images']['width'] = $shop_single_image_size['width'] . 'px';
$css['global']['.product .summary.entry-summary']['margin-left'] = $shop_single_image_size['width'] + 30 . 'px';
}
}
}
}
$elements = array('html', 'body', 'html body.custom-background');
if (class_exists('WooCommerce')) {
$elements[] = '.woocommerce-tabs > .tabs .active a';
}
$css['global'][avada_implode($elements)]['background-color'] = Avada_Sanitize::color(Avada()->settings->get('content_bg_color'));
if ('Wide' == Avada()->settings->get('layout')) {
$css['global'][avada_implode($elements)]['background-color'] = Avada_Sanitize::color(Avada()->settings->get('content_bg_color'));
} elseif ('Boxed' == Avada()->settings->get('layout')) {
$css['global'][avada_implode($elements)]['background-color'] = Avada_Sanitize::color(Avada()->settings->get('bg_color'));
}
if (!$site_width_percent) {
$elements = array('#main', '.fusion-secondary-header', '.sticky-header .sticky-shadow', '.tfs-slider .slide-content-container', '.header-v4 #small-nav', '.header-v5 #small-nav', '.fusion-footer-copyright-area', '.fusion-footer-widget-area', '#slidingbar', '.fusion-page-title-bar');
$css['global'][avada_implode($elements)]['padding-left'] = '30px';
$css['global'][avada_implode($elements)]['padding-right'] = '30px';
$elements = array('.width-100 .nonhundred-percent-fullwidth', '.width-100 .fusion-section-separator');
$css['global'][avada_implode($elements)]['padding-left'] = $hundredplr_padding;
$css['global'][avada_implode($elements)]['padding-right'] = $hundredplr_padding;
$elements = array('.width-100 .fullwidth-box', '.width-100 .fusion-section-separator');
$css['global'][avada_implode($elements)]['margin-left'] = $hundredplr_padding_negative_margin . '!important';
$css['global'][avada_implode($elements)]['margin-right'] = $hundredplr_padding_negative_margin . '!important';
}
$css['global']['.fusion-mobile-menu-design-modern .fusion-mobile-nav-holder li a']['padding-left'] = '30px';
$css['global']['.fusion-mobile-menu-design-modern .fusion-mobile-nav-holder li a']['padding-right'] = '30px';
$css['global']['.fusion-mobile-menu-design-modern .fusion-mobile-nav-holder .fusion-mobile-nav-item .fusion-open-submenu']['padding-right'] = '35px';
$css['global']['.fusion-mobile-menu-design-modern .fusion-mobile-nav-holder .fusion-mobile-nav-item a']['padding-left'] = '30px';
$css['global']['.fusion-mobile-menu-design-modern .fusion-mobile-nav-holder .fusion-mobile-nav-item a']['padding-right'] = '30px';
示例11: wc_get_image_size
<?php
/**
* Single Product Image
*
* @author WooThemes
* @package WooCommerce/Templates
* @version 2.0.14
*/
if (!defined('ABSPATH')) {
exit;
}
// Exit if accessed directly
global $post, $woocommerce, $product;
// set the image container size
$img_size = wc_get_image_size('shop_single');
if (intval($img_size['width']) < $GLOBALS['content_width']) {
$img_size['width'] = intval($img_size['width']) * 100 / $GLOBALS['content_width'];
} else {
$img_size['width'] = 100;
}
?>
<div class="images" style="width:<?php
echo $img_size['width'];
?>
%;">
<?php
if (has_post_thumbnail()) {
$image_title = esc_attr(get_the_title(get_post_thumbnail_id()));
$image_link = wp_get_attachment_url(get_post_thumbnail_id());
示例12: get_image_size
/**
* @deprecated 2.1.0
* @param $image_size
* @return array
*/
public function get_image_size($image_size)
{
_deprecated_function('Woocommerce->get_image_size', '2.1', 'wc_get_image_size()');
return wc_get_image_size($image_size);
}
示例13: lpd_subcategory_thumbnail
function lpd_subcategory_thumbnail($category)
{
$small_thumbnail_size = 'theme-size-1x1';
$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];
} else {
$image = wc_placeholder_img_src();
}
if ($image) {
// Prevent esc_url from breaking spaces in urls for image embeds
// Ref: http://core.trac.wordpress.org/ticket/23605
$image = str_replace(' ', '%20', $image);
echo '<img src="' . esc_url($image) . '" alt="' . esc_attr($category->name) . '" width="' . esc_attr($dimensions['width']) . '" height="' . esc_attr($dimensions['height']) . '" />';
}
}
示例14: has_post_thumbnail
}
// Exit if accessed directly
global $post, $woocommerce, $product;
?>
<div class="images ms-product-slider">
<?php
$attachment_ids = $product->get_gallery_attachment_ids();
$image_count = has_post_thumbnail() ? 1 : 0;
$image_count += count($attachment_ids);
if ($image_count > 1) {
$enable_thumbnail = apply_filters('msp_woocommerce_display_thumbnail_for_single_product_slider', true);
$small_thumbnail_size = apply_filters('single_product_small_single_size', 'shop_thumbnail');
$thumbnail_dimensions = wc_get_image_size($small_thumbnail_size);
$large_single_size = apply_filters('single_product_large_single_size', 'shop_single');
$slide_image_dimensions = wc_get_image_size($large_single_size);
$slider_params = array('id' => $post->ID, 'uid' => '', 'class' => '', 'margin' => 0, 'inline_style' => '', 'bg_color' => '', 'bg_image' => '', 'slider_type' => 'custom', 'width' => $slide_image_dimensions['width'], 'height' => $slide_image_dimensions['height'], 'start' => 1, 'space' => 0, 'grab_cursor' => 'true', 'swipe' => 'true', 'wheel' => 'false', 'mouse' => 'true', 'crop' => 'false', 'autoplay' => 'false', 'loop' => 'false', 'shuffle' => 'false', 'preload' => 2, 'wrapper_width' => '', 'wrapper_width_unit' => 'px', 'layout' => 'fillwidth', 'fullscreen_margin' => 0, 'height_limit' => 'false', 'auto_height' => 'false', 'smooth_height' => 'true', 'end_pause' => 'false', 'over_pause' => 'false', 'fill_mode' => 'fill', 'center_controls' => 'true', 'layers_mode' => 'center', 'hide_layers' => 'false', 'instant_show_layers' => 'false', 'speed' => 17, 'skin' => 'ms-skin-default', 'template' => '', 'template_class' => '', 'direction' => 'h', 'view' => 'basic', 'gfonts' => '', 'parallax_mode' => 'swipe', 'arrows' => 'true', 'arrows_autohide' => 'true', 'arrows_overvideo' => 'true', 'arrows_hideunder' => '', 'bullets' => 'false', 'bullets_autohide' => 'true', 'bullets_overvideo' => 'true', 'bullets_direction' => 'h', 'bullets_align' => 'bottom', 'bullets_margin' => '', 'bullets_hideunder' => '', 'thumbs' => 'false', 'thumbs_autohide' => 'false', 'thumbs_overvideo' => 'true', 'thumbs_direction' => 'h', 'thumbs_type' => 'thumbs', 'thumbs_speed' => 17, 'thumbs_inset' => 'false', 'thumbs_align' => 'bottom', 'thumbs_margin' => 0, 'thumbs_width' => $thumbnail_dimensions['width'], 'thumbs_height' => $thumbnail_dimensions['height'], 'thumbs_space' => 0, 'thumbs_hideunder' => '', 'thumbs_fillmode' => 'fill', 'scroll' => 'false', 'scroll_autohide' => 'true', 'scroll_overvideo' => 'true', 'scroll_direction' => 'h', 'scroll_align' => 'top', 'scroll_inset' => 'true', 'scroll_margin' => '', 'scroll_color' => '#3D3D3D', 'scroll_hideunder' => '', 'scroll_width' => '', 'circletimer' => 'false', 'circletimer_autohide' => 'true', 'circletimer_overvideo' => 'true', 'circletimer_color' => '#A2A2A2', 'circletimer_radius' => 4, 'circletimer_stroke' => 10, 'circletimer_margin' => '', 'circletimer_hideunder' => '', 'timebar' => 'false', 'timebar_autohide' => 'true', 'timebar_overvideo' => 'true', 'timebar_align' => 'bottom', 'timebar_color' => '#FFFFFF', 'timebar_hideunder' => '', 'timebar_width' => '', 'slideinfo' => 'false', 'slideinfo_autohide' => 'true', 'slideinfo_overvideo' => 'true', 'slideinfo_direction' => 'h', 'slideinfo_align' => 'bottom', 'slideinfo_inset' => 'false', 'slideinfo_margin' => '', 'slideinfo_hideunder' => '', 'slideinfo_width' => '', 'slideinfo_height' => '');
if ($enable_thumbnail) {
$slider_params['thumbs'] = 'true';
}
$slider_params = apply_filters('msp_woocommerce_single_product_slider_params', $slider_params, $post);
// create ms_slider shortcode
$slider_attrs = '';
foreach ($slider_params as $attr => $attr_value) {
$slider_attrs .= sprintf('%s="%s" ', $attr, esc_attr($attr_value));
}
$slides = '';
if (has_post_thumbnail()) {
$image_title = esc_attr(get_the_title(get_post_thumbnail_id()));
$image_link = wp_get_attachment_url(get_post_thumbnail_id());
$image_src = msp_get_the_resized_image_src($image_link, $slide_image_dimensions['width'], $slide_image_dimensions['height'], $slide_image_dimensions['crop']);
示例15: addImage_thumbnail
function addImage_thumbnail($filename, $parent_post_id)
{
include_once ABSPATH . 'wp-admin/includes/image.php';
#wp_insert_attachment
include_once ABSPATH . 'wp-includes/class-wp-image-editor.php';
include_once ABSPATH . 'wp-includes/media.php';
#wp_get_image_editor
//Upload Image in uploads folder
// Check the type of tile. We'll use this as the 'post_mime_type'.
$image_size = array();
$wp_upload_dir = @wp_upload_dir();
$content = @file_get_contents($filename);
$upload_file = @wp_upload_bits(basename($filename), null, $content);
$filetype = @wp_check_filetype(basename($filename), null);
$date = date("Y") . '/' . date('m');
$attachment = array('guid' => $wp_upload_dir['url'] . '/' . basename($filename), 'post_mime_type' => $filetype['type'], 'post_title' => preg_replace('/\\.[^.]+$/', '', basename($filename)), 'post_content' => '', 'post_status' => 'inherit');
$image_size['shop_thumbnail'] = wc_get_image_size('shop_thumbnail');
$image_size['shop_catalog'] = wc_get_image_size('shop_catalog');
$image_size['shop_single'] = wc_get_image_size('shop_single');
$fileName = preg_replace('/^.*?\\/(\\d{4})\\/(\\d\\d)\\/(.*)$/', $wp_upload_dir['basedir'] . '/$1/$2/$3', $filename);
foreach ($image_size as $image_key => $size) {
$image = @wp_get_image_editor($fileName);
if (!is_wp_error($image)) {
$image->resize($size['width'], $size['height'], $size['crop']);
$image->save($wp_upload_dir['basedir'] . "/" . $date . '/' . basename($filename, "." . $filetype['ext']) . "-" . $size['width'] . "x" . $size['height'] . "." . $filetype['ext']);
}
$image_size[$image_key]['file'] = basename($filename, "." . $filetype['ext']) . "-" . $size['width'] . "x" . $size['height'] . "." . $filetype['ext'];
$image_size[$image_key]['mime-type'] = $filetype['type'];
// To unset the crop in the array image_size
unset($image_size[$image_key]['crop']);
}
$attach_id = @wp_insert_attachment($attachment, $date . '/' . basename($filename), $parent_post_id);
$attach_data = @wp_generate_attachment_metadata($attach_id, $wp_upload_dir['url'] . '/' . basename($filename));
// Generate the metadata for the attachment, and update the database record.
$attach_data['sizes'] = $image_size;
@wp_update_attachment_metadata($attach_id, $attach_data);
unset($filename);
unset($parent_post_id);
return $attach_id;
}