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


PHP wp_get_attachment_image_sizes函数代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: woocommerce_subcategory_thumbnail

 /**
  * 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']) . '" />';
         }
     }
 }
开发者ID:woocommerce,项目名称:woocommerce,代码行数:32,代码来源:wc-template-functions.php

示例6: apply_filters

         echo apply_filters('the_content', $wysiwyg);
     }
     break;
     //
     // Image
     //
 //
 // Image
 //
 case 'fullwidth_image':
     $image_ID = get_post_meta($talk_ID, 'uxr_talk_transcript_' . $count . '_fullwidth_image', true);
     if (isset($image_ID) && !empty($image_ID)) {
         // Image source
         $img_src = wp_get_attachment_image_url($image_ID, 'uxr_fullwidth');
         $img_srcset = wp_get_attachment_image_srcset($image_ID, 'uxr_fullwidth');
         $img_sizes = wp_get_attachment_image_sizes($image_ID, 'uxr_fullwidth');
         // 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, 'uxr_fullwidth');
         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;
     //
     // Links
     //
 //
开发者ID:kReEsTaL,项目名称:uxrennes-wp-theme,代码行数:31,代码来源:content-events.php

示例7: wp_img_add_srcset_and_sizes

/**
 * 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;
}
开发者ID:kprajapatii,项目名称:WordPress,代码行数:67,代码来源:media.php

示例8: get_available_variation

 /**
  * 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);
 }
开发者ID:jesusmarket,项目名称:jesusmarket,代码行数:34,代码来源:class-wc-product-variable.php

示例9: 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") {
                 echo "<p>";
开发者ID:meowrika,项目名称:govintranet,代码行数:67,代码来源:ht_feature_news.php

示例10: _carelib_image_get_sizes

/**
 * Retrieves the value for an image attachment’s ‘sizes’ 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 'sizes' value string or false.
 */
function _carelib_image_get_sizes($id, $args)
{
    if (!$args['responsive'] || !function_exists('wp_get_attachment_image_srcset')) {
        return false;
    }
    return wp_get_attachment_image_sizes($id, $args['size']);
}
开发者ID:wpsitecare,项目名称:carelib,代码行数:16,代码来源:image.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: msx_card_deck_carousel

/**
 * Display deck of cards using Bootstrap's carousel
 *
 * @param int   $deck The ID of the card deck.
 * @param array $args Array of arguments to affect output.
 */
function msx_card_deck_carousel($deck, $args = array())
{
    $defaults = array('container_class' => 'carousel slide', 'container_id' => 'carousel-' . $deck, 'deck_class' => 'carousel-inner msx-card-deck', 'deck_id' => 'msx-card-deck-' . $deck, 'card_class' => 'item', 'image_size' => 'full', 'indicators' => true, 'controls' => false);
    $args = wp_parse_args($args, $defaults);
    $deck = (int) $deck;
    $card_deck = get_post($deck);
    if (!empty($card_deck)) {
        $output = '';
        $deck_custom = get_post_custom($card_deck->ID);
        $cards_list = explode(',', $deck_custom['cards_order'][0]);
        $cards = get_posts(array('post_type' => 'msx_card', 'post__in' => $cards_list, 'orderby' => 'post__in', 'order' => 'ASC'));
        // Add the carousel wrapper.
        $output .= '<div class="' . $args['container_class'] . '" id="' . $args['container_id'] . '" data-ride="carousel">';
        // Display indicators.
        if (!false == $args['indicators']) {
            $i = 0;
            $output .= '<ol class="carousel-indicators">';
            foreach ($cards as $card) {
                if (!empty($card)) {
                    if (0 == $i) {
                        $output .= '<li data-target="#' . $args['container_id'] . '" data-slide-to="0" class="active"></li>';
                    } else {
                        $output .= '<li data-target="#' . $args['container_id'] . '" data-slide-to="' . $i . '"></li>';
                    }
                    $i++;
                }
            }
            $output .= '</ol>';
        }
        // Start the decks of cards.
        $output .= '<div class="' . $args['deck_class'] . '" id="' . $args['deck_id'] . '">';
        // Display the cards.
        $c = 0;
        foreach ($cards as $card) {
            if (!empty($card)) {
                $c++;
                $custom = get_post_custom($card->ID);
                $format = get_post_format($card->ID);
                $card_class = 1 == $c ? $args['card_class'] . ' active' : $args['card_class'];
                $output .= sprintf('<div class="%1$s msx-card msx-card-%2$s" id="msx-card-%3$s">', $card_class, $format, $card->ID);
                switch ($format) {
                    case 'image':
                        $img_src = wp_get_attachment_image_url($custom['image'][0], $args['image_size']);
                        $img_src_set = wp_get_attachment_image_srcset($custom['image'][0], $args['image_size']);
                        $img_sizes = wp_get_attachment_image_sizes($custom['image'][0], $args['image_size']);
                        $output .= !empty($custom['target'][0]) ? '<a href="' . $custom['target'][0] . '" title="' . $card->post_title . '">' : '';
                        $output .= sprintf('<img src="%1$s" srcset="%2$s" sizes="%3$s" alt="%4$s">', $img_src, $img_src_set, $img_sizes, $card->post_title);
                        $output .= !empty($custom['target'][0]) ? '</a>' : '';
                        break;
                    case 'video':
                        $video_meta = wp_get_attachment_metadata($custom['video'][0]);
                        $video_url = wp_get_attachment_url($custom['video'][0]);
                        $video_source = sprintf('<source src="%1$s" type="%2$s">', $video_url, get_post_mime_type($custom['video'][0]));
                        $image = wp_get_attachment_image_src(get_post_thumbnail_id($card->ID), $args['image_size']);
                        $output .= sprintf('<video width="%1$s" height="%2$s" poster="%3$s" controls>%4$s</video>', $video_meta['width'], $video_meta['height'], $image[0], $video_source);
                        break;
                    case 'link':
                        if (!empty($custom['video'][0])) {
                            $output .= '<div class="embed-responsive embed-responsive-16by9">';
                            $output .= '<iframe src="' . $custom['video'][0] . '" autoload noborder></iframe>';
                            $output .= '</div>';
                        }
                        break;
                }
                $output .= '<div class="carousel-caption">';
                $output .= '<h4 class="msx-card-title">' . $card->post_title . '</h4>';
                $output .= '<p class="msx-card-content">' . $card->post_content . '</p>';
                $output .= '</div>';
                $output .= '</div>';
            }
        }
        // End the deck of cards.
        $output .= '</div>';
        if (!false == $args['controls']) {
            $output .= '<a class="left carousel-control" href="#' . $args['container_id'] . '" role="button" data-slide="prev">';
            $output .= '<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>';
            $output .= '<span class="sr-only">Previous</span>';
            $output .= '</a>';
            $output .= '<a class="right carousel-control" href="#' . $args['container_id'] . '" role="button" data-slide="next">';
            $output .= '<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>';
            $output .= '<span class="sr-only">Next</span>';
            $output .= '</a>';
        }
        $output .= '</div>';
        echo $output;
    }
}
开发者ID:starverte,项目名称:matchstix,代码行数:93,代码来源:msx-card-deck.php

示例13: the_content

        echo '<div class="wpcw_fe_progress_box_wrap"><div class="wpcw_fe_progress_box wpcw_fe_progress_box_error">Please log in to access these videos. <a class="button orange" href="/wp-admin/">Log in here</a></div></div>';
    }
    the_content();
    // WP_Query arguments
    $args = array('post_parent' => $post->ID, 'post_type' => array('page'), 'orderby' => 'menu_order', 'order' => 'ASC');
    // The Query
    $modules_query = new WP_Query($args);
    // The Loop
    if ($modules_query->have_posts()) {
        echo '<section class="module-container">';
        while ($modules_query->have_posts()) {
            $modules_query->the_post();
            $landing_page_image = get_field('landing_page_image');
            echo '<section class="module ' . $post->post_name . '">';
            echo '<a href="' . get_permalink() . '">';
            echo '<img src="' . esc_url($landing_page_image['url']) . '" alt="' . esc_attr($landing_page_image['alt']) . '" srcset="' . esc_attr(wp_get_attachment_image_srcset($landing_page_image['id'])) . '" sizes="' . esc_attr(wp_get_attachment_image_sizes($landing_page_image['id'])) . '" />';
            echo '<h2>' . get_the_title() . '</h2>';
            echo '</a>';
            echo '</section>';
        }
        echo '</section><!-- .module-container -->';
    }
    // Restore original Post Data
    wp_reset_postdata();
    ?>
                </div><!-- .entry-content -->

                <?php 
    edit_post_link(sprintf(__('Edit<span class="screen-reader-text"> "%s"</span>', 'twentysixteen'), the_title('', '', false)), '<footer class="entry-footer"><span class="edit-link">', '</span></footer><!-- .entry-footer -->');
    ?>
开发者ID:macbookandrew,项目名称:WWNTBM-MOS,代码行数:30,代码来源:template-mos.php

示例14: build_responsive_image_meta

/** 
 * Build responsive image meta
 */
function build_responsive_image_meta($media_id, $size_max = 'full', $size_small = 'medium')
{
    // Get meta
    $media_meta = wp_get_attachment_metadata($media_id);
    $return = ['srcset' => wp_get_attachment_image_srcset($media_id, $size_max, $media_meta), 'size' => wp_get_attachment_image_sizes($media_id, $size_max), 'src' => wp_get_attachment_image_src($media_id, $size_small), 'meta' => $media_meta];
    //$return['meta']['caption'] = get_the_excerpt( $media_id );
    //print_r($return);die();
    return $return;
}
开发者ID:proudcity,项目名称:wp-proud-core,代码行数:12,代码来源:proud-helpers.php

示例15: get_image

 /**
  * Get the HTML for the image attached to this menu item
  *
  * Any set img ID will override image src filtering
  * 
  * @return string img HTML
  */
 function get_image()
 {
     //Ignore mobile?
     if ($this->get_menu_op('disable_images_mobile') == 'on' && ubermenu_is_mobile('disable_images_mobile')) {
         return '';
     }
     //Image
     $img = apply_filters('ubermenu_item_image', '', $this);
     if ($img) {
         return $img;
     }
     //Allow ID filtering
     $img_id = apply_filters('ubermenu_item_image_id', $this->getSetting('item_image'), $this);
     //Allow src filtering
     $img_src = apply_filters('ubermenu_item_image_src', '', $this);
     //Inherit featured image dynamically
     if ($this->getSetting('inherit_featured_image') == 'on') {
         if ($this->item->type == 'post_type') {
             $thumb_id = get_post_thumbnail_id($this->item->object_id);
             if ($thumb_id) {
                 $img_id = $thumb_id;
             }
         }
     }
     if ($img_id || $img_src) {
         $atts = array();
         $img_srcset = $img_sizes = '';
         $atts['class'] = 'ubermenu-image';
         //Determine size of image to get
         $img_size = $this->getSetting('image_size');
         if ($img_size == 'inherit') {
             $img_size = $this->get_menu_op('image_size');
         }
         //echo '['.$img_size.']';
         $atts['class'] .= ' ubermenu-image-size-' . $img_size;
         //If the img_id is set, get the right image src file
         if ($img_id) {
             $img_src = wp_get_attachment_image_src($img_id, $img_size);
             if (function_exists('wp_get_attachment_image_srcset')) {
                 $img_srcset = wp_get_attachment_image_srcset($img_id, $img_size);
                 $img_sizes = wp_get_attachment_image_sizes($img_id, $img_size);
             }
         }
         //Lazy Load
         if ($this->depth > 0 && $this->get_menu_op('lazy_load_images') == 'on') {
             $atts['class'] .= ' ubermenu-image-lazyload';
             $atts['data-src'] = $img_src[0];
             if ($img_srcset) {
                 $atts['data-srcset'] = $img_srcset;
                 if ($img_sizes) {
                     $atts['data-sizes'] = $img_sizes;
                 }
             }
         } else {
             $atts['src'] = $img_src[0];
             if ($img_srcset) {
                 $atts['srcset'] = $img_srcset;
                 if ($img_sizes) {
                     $atts['sizes'] = $img_sizes;
                 }
             }
         }
         //Determine dimensions
         $img_w = '';
         $img_h = '';
         $dimensions = $this->getSetting('image_dimensions');
         switch ($dimensions) {
             //Custom Dimensions use Menu Item Settings
             case 'custom':
                 $img_w = $this->getSetting('image_width_custom');
                 $img_h = $this->getSetting('image_height_custom');
                 break;
                 //Inherit settings from main Menu Settings
             //Inherit settings from main Menu Settings
             case 'inherit':
                 $img_w = $this->get_menu_op('image_width');
                 $img_h = $this->get_menu_op('image_height');
                 break;
                 //Add width and height atts for natural width
             //Add width and height atts for natural width
             case 'natural':
                 //Done below
                 break;
             default:
                 break;
         }
         //Apply natural dimensions if not already set
         if ($this->get_menu_op('image_set_dimensions')) {
             if ($img_w == '' && $img_h == '') {
                 $img_w = $img_src[1];
                 $img_h = $img_src[2];
             }
         }
//.........这里部分代码省略.........
开发者ID:Wordpress-Development,项目名称:Installation-Setup,代码行数:101,代码来源:UberMenuItem.class.php


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