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


PHP wp_get_attachment_image函数代码示例

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


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

示例1: display_media

 public function display_media($location, $fallback = true, $fallbackhome = false)
 {
     global $post;
     ob_start();
     $media = $this->query_attachments($post->ID, $location);
     if (!$media->have_posts() && $fallback == true) {
         $media = $this->query_attachments($post->post_parent, $location);
     }
     if (!$media->have_posts() && $fallbackhome == true) {
         $frontpage_id = get_option('page_on_front');
         $media = $this->query_attachments($frontpage_id, $location);
     }
     if ($media->have_posts()) {
         while ($media->have_posts()) {
             $media->the_post();
             $media_info = get_post_custom(get_the_ID());
             if (isset($media_info['image_link']) && $media_info['image_link'][0]) {
                 echo '<a href="' . $media_info['image_link'][0] . '">';
             }
             echo wp_get_attachment_image(get_the_ID(), 'full');
             if (isset($media_info['image_link']) && $media_info['image_link'][0]) {
                 echo '</a>';
             }
         }
         wp_reset_postdata();
     } else {
         return false;
     }
     return ob_get_clean();
 }
开发者ID:jemjabella,项目名称:media-locations,代码行数:30,代码来源:class.frontend.php

示例2: my_custom_columns

function my_custom_columns($column)
{
    global $post;
    // Bildstorlek
    $width = (int) 200;
    $height = (int) 125;
    if ('ID' == $column) {
        echo $post->ID;
    } elseif ('thumbnail' == $column) {
        // thumbnail of WP 2.9
        $thumbnail_id = get_post_meta($post->ID, '_thumbnail_id', true);
        // image from gallery
        $attachments = get_children(array('post_parent' => $post_id, 'post_type' => 'attachment', 'post_mime_type' => 'image'));
        if ($thumbnail_id) {
            $thumb = wp_get_attachment_image($thumbnail_id, array($width, $height), true);
        } elseif ($attachments) {
            foreach ($attachments as $attachment_id => $attachment) {
                $thumb = wp_get_attachment_image($attachment_id, array($width, $height), true);
            }
        }
        if (isset($thumb) && $thumb) {
            echo $thumb;
        } else {
            echo __('None');
        }
    } elseif ('description' == $column) {
        echo $post->post_content;
    }
}
开发者ID:Jonatan,项目名称:makthavare,代码行数:29,代码来源:makthavare.php

示例3: wpthumb_img_shortcode

function wpthumb_img_shortcode($args)
{
    $args_attrs = array('class', 'alt');
    $attrs = array();
    foreach ($args_attrs as $att) {
        if (isset($args[$att])) {
            $attrs[$att] = $args[$att];
            unset($args[$att]);
        }
    }
    if (is_numeric($args[0])) {
        $attachment_id = $args[0];
        unset($args[0]);
        return wp_get_attachment_image($attachment_id, $args, false, $attrs);
    } else {
        if (!empty($args)) {
            $url = esc_url($args[0]);
            unset($args[0]);
            $image = wpthumb($url, $args);
            list($width, $height) = getimagesize($image);
            $attr = '';
            foreach ($attrs as $a => $value) {
                $attr .= ' ' . $a . '="' . esc_attr($value) . '"';
            }
            return '<img src="' . $image . '" width="' . $width . '" height="' . $height . '"' . $attr . ' />';
        }
    }
}
开发者ID:RA2WP,项目名称:RA2WP,代码行数:28,代码来源:wpthumb.shortcodes.php

示例4: ya_product_thumbnail

function ya_product_thumbnail($size = 'shop_catalog', $placeholder_width = 0, $placeholder_height = 0)
{
    global $post;
    $html = '';
    $id = get_the_ID();
    $gallery = get_post_meta($id, '_product_image_gallery', true);
    $attachment_image = '';
    if (!empty($gallery)) {
        $gallery = explode(',', $gallery);
        $first_image_id = $gallery[0];
        $attachment_image = wp_get_attachment_image($first_image_id, $size, false, array('class' => 'hover-image back'));
    }
    $image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), '');
    if (has_post_thumbnail()) {
        if ($attachment_image) {
            $html .= '<div class="product-thumb-hover">';
            $html .= get_the_post_thumbnail($post->ID, $size) ? get_the_post_thumbnail($post->ID, $size) : '<img src="' . get_template_directory_uri() . '/assets/img/placeholder/' . $size . '.png" alt="No thumb">';
            $html .= $attachment_image;
            $html .= '</div>';
            /* quickview */
            $nonce = wp_create_nonce("ya_quickviewproduct_nonce");
            $link = admin_url('admin-ajax.php?ajax=true&amp;action=ya_quickviewproduct&amp;post_id=' . $post->ID . '&amp;nonce=' . $nonce);
            $html .= '<a href="' . $link . '" data-fancybox-type="ajax" class="group fancybox fancybox.ajax">' . apply_filters('out_of_stock_add_to_cart_text', __('Quick View ', 'yatheme')) . '</a>';
        } else {
            $html .= get_the_post_thumbnail($post->ID, $size) ? get_the_post_thumbnail($post->ID, $size) : '<img src="' . get_template_directory_uri() . '/assets/img/placeholder/' . $size . '.png" alt="No thumb">';
        }
        return $html;
    } else {
        $html .= '<img src="' . get_template_directory_uri() . '/assets/img/placeholder/' . $size . '.png" alt="No thumb">';
        return $html;
    }
}
开发者ID:junibrosas,项目名称:shoppingyourway,代码行数:32,代码来源:woocommerce-hook.php

示例5: thb_image

function thb_image($atts, $content = null)
{
    extract(shortcode_atts(array('image' => '', 'target_blank' => false, 'img_size' => 'thumbnail', 'img_link' => '', 'img_link_target' => '', 'alignment' => '', 'lightbox' => '', 'size' => 'small', 'animation' => false), $atts));
    $img_id = preg_replace('/[^\\d]/', '', $image);
    //$img = wpb_getImageBySize(array( 'attach_id' => $img_id, 'thumb_size' => $img_size, 'class' => $animation ));
    $img = wp_get_attachment_image($img_id, $img_size, false, array('class' => $animation . ' ' . $alignment, 'alt' => trim(strip_tags(get_post_meta($img_id, '_wp_attachment_image_alt', true)))));
    if ($img == NULL) {
        $img = '<img src="http://placekitten.com/g/400/300" />';
    }
    $link_to = $c_lightbox = '';
    if ($lightbox == true) {
        $link_to = wp_get_attachment_image_src($img_id, 'large');
        $link_to = $link_to[0];
        $c_lightbox = ' rel="magnific"';
    } else {
        if (!empty($img_link)) {
            $link_to = $img_link;
        }
    }
    if (!empty($link_to) && !preg_match('/^(https?\\:\\/\\/|\\/\\/)/', $link_to)) {
        $link_to = 'http://' . $link_to;
    }
    $out = !empty($link_to) ? '<a ' . $c_lightbox . ' href="' . $link_to . '"' . ($target_blank ? ' target="_blank"' : '') . '>' . $img . '</a>' : $img;
    return $out;
}
开发者ID:ConceptHaus,项目名称:beckery,代码行数:25,代码来源:thb_image.php

示例6: element

 function element()
 {
     $style = $this->opt('style') ? $this->opt('style') : '';
     $image = $this->opt('image') ? $this->opt('image') : '';
     $click_action = $this->opt('click_action') ? $this->opt('click_action') : '';
     $image_alignment = $this->opt('image_alignment') ? $this->opt('image_alignment') : '';
     //** Appear animation
     $appear_delay = $this->opt('appear_delay') ? $this->opt('appear_delay') : '0';
     $appear = $this->opt('appear_animation') ? $this->opt('appear_animation') : '';
     if (!empty($appear)) {
         $appear = 'data-appear="fade-in" data-appear-direction="' . $appear . '" data-appear-delay="' . $appear_delay . '"';
     }
     if (empty($image)) {
         echo '<div class="zn-pb-notification">Please configure the element and add an image.</div>';
         return;
     }
     //$link = $this->opt('link');
     //$link_extracted = !empty( $link ) ? zn_extract_link( $this->opt('link') , '' ) : '';
     $link_extracted = zn_extract_link($this->opt('link'));
     if ($click_action === 'popup') {
         $image_src = wp_get_attachment_image($image, 'full', false, array('class' => 'img-responsive animate magPopupImg ' . $image_alignment . '', 'data-mfp-src' => wp_get_attachment_url($image)));
     } else {
         if ($click_action === 'link') {
             $image_src = $link_extracted['start'] . wp_get_attachment_image($image, 'full', false, array('class' => 'img-responsive animate ' . $image_alignment . '')) . $link_extracted['end'];
         } else {
             $image_src = wp_get_attachment_image($image, 'full', false, array('class' => 'img-responsive ' . $image_alignment . ''));
         }
     }
     echo '<div class="znImageContainer clearfix ' . $this->data['uid'] . '" ' . $appear . '>';
     //echo '<img alt="Image" src="'.$image.'" class="img-responsive animate">';
     echo '<div class="znImgSubcontainer ' . (empty($click_action) ? '' : 'scaleRotateImg') . '">';
     echo $image_src;
     echo '</div>';
     echo '</div>';
 }
开发者ID:fjbeteiligung,项目名称:development,代码行数:35,代码来源:image.php

示例7: tb_ad_featured_thumbnail

 function tb_ad_featured_thumbnail()
 {
     global $post;
     // go see if any images are associated with the ad
     $image_id = cp_get_featured_image_id($post->ID);
     // set the class based on if the hover preview option is set to "yes"
     if (get_option('cp_ad_image_preview') == 'yes') {
         $prevclass = 'preview';
     } else {
         $prevclass = 'nopreview';
     }
     if ($image_id > 0) {
         // get 50x50 v3.0.5+ image size
         $adthumbarray = wp_get_attachment_image($image_id, 'ad-small');
         // grab the large image for onhover preview
         $adlargearray = wp_get_attachment_image_src($image_id, 'large');
         $img_large_url_raw = $adlargearray[0];
         // must be a v3.0.5+ created ad
         if ($adthumbarray) {
             echo '<a href="' . get_permalink() . '" title="' . the_title_attribute('echo=0') . '" class="' . $prevclass . '" data-rel="' . $img_large_url_raw . '">' . $adthumbarray . '</a>';
             // maybe a v3.0 legacy ad
         } else {
             $adthumblegarray = wp_get_attachment_image_src($image_id, 'ad-small');
             $img_thumbleg_url_raw = $adthumblegarray[0];
             echo '<a href="' . get_permalink() . '" title="' . the_title_attribute('echo=0') . '" class="' . $prevclass . '" data-rel="' . $img_large_url_raw . '">' . $adthumblegarray . '</a>';
         }
         // no image so return the placeholder thumbnail
     } else {
         echo '<a href="' . get_permalink() . '" title="' . the_title_attribute('echo=0') . '"><img class="attachment-sidebar-thumbnail" alt="" title="" src="' . get_stylesheet_directory_uri() . '/images/no-thumb-100.jpg" /></a>';
     }
 }
开发者ID:joslec9,项目名称:Job-posting-page,代码行数:31,代码来源:functions.php

示例8: theme2_gallery

function theme2_gallery($attr, $text = '')
{
    // var_dump($attr);
    $img_src = explode(',', $attr['ids']);
    // print_r($img_src);
    $pattern = '#(width|height)="\\d+"#';
    $return = '<ul id="slide_2" class="slidik">';
    $i = 1;
    foreach ($img_src as $key) {
        //получаем хтмл картинки
        $img_url = wp_get_attachment_image($key, 'full');
        // вырезаем атрибуты ширины и высоты
        $img_url = preg_replace($pattern, '', $img_url);
        if ($i == 1) {
            $return .= '<li class="show">' . $img_url . '</li>';
        } else {
            $return .= '<li>' . $img_url . '</li>';
        }
        $i++;
    }
    $return .= '<a data-slidik="slide_2" class="next" href="#">Next</a>
            <a data-slidik="slide_2" class="prev" href="#">Prev</a>
            <div class="captionWrap"><div data-slidik="slide_2" class="caption"></div></div>
            <div class="portfolio-close"><a href="#"></a></div>
        </ul>';
    echo "{$return}";
}
开发者ID:ipixby,项目名称:wp2,代码行数:27,代码来源:functions.php

示例9: mm_posts_output_custom_post_image_simple_image_content

/**
 * Custom Image Output for Simple Image & Content template.
 */
function mm_posts_output_custom_post_image_simple_image_content($post, $context, $args)
{
    $custom_output = apply_filters('mm_posts_post_image', '', $post, $context, $args);
    if ('' !== $custom_output) {
        echo $custom_output;
        return;
    }
    // Default to using the 'post-thumbnail' size.
    if ('' !== $args['featured_image_size']) {
        $image_size = esc_attr($args['featured_image_size']);
    } else {
        $image_size = 'post-thumbnail';
    }
    // Check for existing featured image
    if (has_post_thumbnail($post->ID)) {
        $image_tag = get_the_post_thumbnail($post->ID, $image_size);
    } else {
        $fallback_image = $args['fallback_image'];
        // Support the fallback image
        if (is_numeric($fallback_image)) {
            $image_tag = wp_get_attachment_image($fallback_image, $image_size);
        }
    }
    // Output image with/without link
    if (mm_true_or_false($args['link_title'])) {
        printf('<div class="entry-image"><a href="%s">%s</a></div>', get_permalink($post->ID), $image_tag);
    } else {
        printf('<div class="entry-image">%s</div>', $image_tag);
    }
}
开发者ID:jgonzo127,项目名称:mm-components,代码行数:33,代码来源:simple-image-content.php

示例10: theme2_gallery

/**
*	shortcode_gallery
**/
function theme2_gallery($attr, $text = '')
{
    // получить массив ID картинок
    $img_src = explode(',', $attr['ids']);
    // шаблон удаления атрибутов width/height
    $pattern = '#(width|height)="\\d+"#';
    $return = '<ul id="slide_2" class="slidik">';
    //счетчик
    $i = 1;
    foreach ($img_src as $item) {
        $image_url = wp_get_attachment_image($item, 'full');
        //delete width and height
        $image_url = preg_replace($pattern, "", $image_url);
        //формируем вывод
        if ($i == 1) {
            $return .= '<li class="show">' . $image_url . '</li>';
        } else {
            $return .= '<li>' . $image_url . '</li>';
        }
        $i++;
    }
    $return .= '<a data-slidik="slide_2" class="next" href="#">Next</a>
			<a data-slidik="slide_2" class="prev" href="#">Prev</a>
			<div class="captionWrap"><div data-slidik="slide_2" class="caption"></div></div>
			<div class="portfolio-close"><a href="portfolio.html"></a></div>			
		</ul>';
    echo $return;
}
开发者ID:Aliot26,项目名称:WP,代码行数:31,代码来源:functions.php

示例11: get_markup

 public function get_markup()
 {
     if (empty($this->attachment_id)) {
         $this->markup = '';
     }
     $this->markup = wp_get_attachment_image($this->attachment_id, $this->image_size, $this->icon, $this->attributes);
 }
开发者ID:Clark-Nikdel-Powell,项目名称:Pattern-Library,代码行数:7,代码来源:image.php

示例12: ocwssl_wp_post_thumbnail_html

function ocwssl_wp_post_thumbnail_html($thumbnail_id = null, $post = null)
{
    global $content_width, $_wp_additional_image_sizes;
    $post = get_post($post);
    $post_type_object = get_post_type_object($post->post_type);
    $set_thumbnail_link = '<p class="hide-if-no-js"><a title="%s" href="%s" id="set-post-thumbnail" class="thickbox">%s</a></p>';
    $upload_iframe_src = get_upload_iframe_src('image', $post->ID);
    $content = sprintf($set_thumbnail_link, esc_attr($post_type_object->labels->set_featured_image), esc_url($upload_iframe_src), esc_html($post_type_object->labels->set_featured_image));
    if ($thumbnail_id && get_post($thumbnail_id)) {
        $old_content_width = $content_width;
        $content_width = 1000;
        if (!isset($_wp_additional_image_sizes['full'])) {
            // use 'full' for system defined fullsize image OR use our custom image size instead of 'post-thumbnail'
            $thumbnail_html = wp_get_attachment_image($thumbnail_id, array($content_width, $content_width));
        } else {
            $thumbnail_html = wp_get_attachment_image($thumbnail_id, 'full');
        }
        // use 'full' for system defined fullsize image OR use our custom image size instead of 'post-thumbnail'
        if (!empty($thumbnail_html)) {
            $ajax_nonce = wp_create_nonce('set_post_thumbnail-' . $post->ID);
            $content = sprintf($set_thumbnail_link, esc_attr($post_type_object->labels->set_featured_image), esc_url($upload_iframe_src), $thumbnail_html);
            $content .= '<p class="hide-if-no-js"><a href="#" id="remove-post-thumbnail" onclick="WPRemoveThumbnail(\'' . $ajax_nonce . '\');return false;">' . esc_html($post_type_object->labels->remove_featured_image) . '</a></p>';
        }
        $content_width = $old_content_width;
    }
    /**
     * Filter the admin post thumbnail HTML markup to return.
     *
     * @since 2.9.0
     *
     * @param string $content Admin post thumbnail HTML markup.
     * @param int    $post_id Post ID.
     */
    return apply_filters('admin_post_thumbnail_html', $content, $post->ID);
}
开发者ID:pftaylor61,项目名称:ocws-slider,代码行数:35,代码来源:ocws-slider.php

示例13: bb_get_attachment_id_from_url

function bb_get_attachment_id_from_url($attachment_url = '', $size = null)
{
    global $wpdb;
    $attachment_id = false;
    // If there is no url, return.
    if ('' == $attachment_url) {
        return;
    }
    // Get the upload directory paths
    $upload_dir_paths = wp_upload_dir();
    // Make sure the upload path base directory exists in the attachment URL, to verify that we're working with a media library image
    if (false !== strpos($attachment_url, $upload_dir_paths['baseurl'])) {
        // If this is the URL of an auto-generated thumbnail, get the URL of the original image
        $attachment_url = preg_replace('/-\\d+x\\d+(?=\\.(jpg|jpeg|png|gif)$)/i', '', $attachment_url);
        // Remove the upload path base directory from the attachment URL
        $attachment_url = str_replace($upload_dir_paths['baseurl'] . '/', '', $attachment_url);
        //$attachment_url = strstr( $attachment_url, '-', true );
        // Finally, run a custom database query to get the attachment ID from the modified attachment URL
        $attachment_id = $wpdb->get_var($wpdb->prepare("SELECT wposts.ID FROM {$wpdb->posts} wposts, {$wpdb->postmeta} wpostmeta WHERE wposts.ID = wpostmeta.post_id AND wpostmeta.meta_key = '_wp_attached_file' AND wpostmeta.meta_value = '%s' AND wposts.post_type = 'attachment'", $attachment_url));
    }
    //prar("Size: $size");
    if ($size) {
        $image = wp_get_attachment_image($attachment_id, $size);
        //prar($image);
        return $image;
    } else {
        return $attachment_id;
    }
}
开发者ID:perkster,项目名称:bear-bones,代码行数:29,代码来源:page.php

示例14: widget

    function widget($args, $instance)
    {
        // Widget output
        $args = array('numberposts' => 1, 'offset' => 0, 'category' => 0, 'orderby' => 'post_date', 'order' => 'DESC', 'post_status' => 'publish', 'suppress_filters' => true);
        $recent_posts = wp_get_recent_posts($args, ARRAY_A);
        $thumb_url = wp_get_attachment_image(get_post_thumbnail_id($recent_posts[0]['ID']), array(194, 220), true);
        ?>

        <div class="blog">
            <div class="blog-image">
                <img src="<?php 
        echo get_template_directory_uri();
        ?>
/img/blog.png"/>
            </div>
            <div class="image">
                <?php 
        echo $thumb_url;
        ?>

            </div>
            <div class="content">
                <?php 
        echo $recent_posts[0]['post_excerpt'];
        ?>

                <a href="<?php 
        echo get_permalink($recent_posts[0]['ID']);
        ?>
">Read more</a>
            </div>
        </div>
        <?php 
    }
开发者ID:rongandat,项目名称:sallumeh,代码行数:34,代码来源:lastestBlog.php

示例15: as_tours_cats_custom_field

function as_tours_cats_custom_field()
{
    $t_id = $_GET['tag_ID'];
    $images = get_option('as_tour_cats_featured_images');
    if ($images === FALSE) {
        $image = array();
    }
    $image = isset($images[$t_id]) ? $images[$t_id] : '';
    ?>
    <table class="form-table">
        <tr class="form-field">
            <th valign="top" scope="row">
                <label>Featured Image</label>
            </th>
            <td>
                <input id="as-tour-cats-featured-image" type="hidden" name="as_tour_cats_featured_image" readonly="readonly" value="<?php 
    echo $image;
    ?>
" />
                <input id="as-tour-cats-remove-image" class="button" type="button" value="Remove image" />
                <input id="as-tour-cats-change-image" class="button" type="button" value="Change image" />
                <div id="as-tour-cats-thumbnail"><?php 
    if (!empty($image)) {
        echo wp_get_attachment_image($image);
    }
    ?>
</div>
                <p class="description">Set a featured image for all the post of this category without a featured image.</p>
            </td>
        </tr>
    </table>
    <?php 
}
开发者ID:bibiangel1989,项目名称:vespatour,代码行数:33,代码来源:tours-categories.php


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