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(); }
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; } }
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 . ' />'; } } }
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&action=ya_quickviewproduct&post_id=' . $post->ID . '&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; } }
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; }
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>'; }
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>'; } }
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}"; }
/** * 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); } }
/** * 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; }
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); }
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); }
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; } }
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 }
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 }
/** DistinctPress Get Image*/ function distinctpress_get_image($args = array()) { global $post; /** Arguments */ $defaults = array('format' => 'html', 'size' => 'full', 'num' => 0, 'attr' => ''); $args = wp_parse_args($args, $defaults); /** WordPress built-in method */ if (has_post_thumbnail() && $args['num'] === 0) { $id = get_post_thumbnail_id(); $html = wp_get_attachment_image($id, $args['size'], false, $args['attr']); list($url) = wp_get_attachment_image_src($id, $args['size'], false, $args['attr']); } else { $id = distinctpress_get_image_id($args['num']); $html = wp_get_attachment_image($id, $args['size'], false, $args['attr']); list($url) = wp_get_attachment_image_src($id, $args['size'], false, $args['attr']); } /** Source path, relative to the root */ $src = str_replace(home_url(), '', $url); /** Output Logic */ if (strtolower($args['format']) == 'html') { $output = $html; } else { if (strtolower($args['format']) == 'url') { $output = $url; } else { $output = $src; } } /** return FALSE if $url is blank */ if (empty($url)) { $output = FALSE; } /** return output */ return $output; }
function photoline_modified_post_gallery($output, $attr) { global $post; static $instance = 0; $instance++; //disable all filter if (empty($attr['type']) || $attr['type'] != 'slider') { return; } if (isset($attr['orderby'])) { $attr['orderby'] = sanitize_sql_orderby($attr['orderby']); if (!$attr['orderby']) { unset($attr['orderby']); } } extract(shortcode_atts(array('order' => 'ASC', 'orderby' => 'menu_order ID', 'id' => $post->ID, 'size' => 'photoline-featured', 'include' => '', 'exclude' => ''), $attr)); $id = intval($id); if ('RAND' == $order) { $orderby = 'none'; } if (!empty($include)) { $include = preg_replace('/[^0-9,]+/', '', $include); $_attachments = get_posts(array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby)); $attachments = array(); foreach ($_attachments as $key => $val) { $attachments[$val->ID] = $_attachments[$key]; } } elseif (!empty($exclude)) { $exclude = preg_replace('/[^0-9,]+/', '', $exclude); $attachments = get_children(array('post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby)); } else { $attachments = get_children(array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby)); } if (empty($attachments)) { return ''; } if (is_feed()) { $output = "\n"; foreach ($attachments as $att_id => $attachment) { $output .= wp_get_attachment_link($att_id, $size, true) . "\n"; } return $output; } $selector = "gallery-{$instance}"; $size_class = sanitize_html_class($size); $gallery_div = "<div id='{$selector}' class='gallery galleryid-{$id} gallery-size-{$size_class} flexslider'>"; $output = apply_filters('gallery_style', $gallery_div); $output .= '<ul class="slides">'; $i = 0; foreach ($attachments as $id => $attachment) { $caption = !empty($attachment->post_excerpt) ? '<p class="flex-caption wp-caption-text gallery-caption">' . wptexturize($attachment->post_excerpt) . '</p>' : ''; $image = wp_get_attachment_image($id, $size); $output .= '<li>'; $output .= $image; $output .= $caption; $output .= '</li>'; } $output .= "\r\n </ul><!-- .slides -->\r\n </div>\n"; return $output; }
/** * Get the thumbnail image for a post's image * * Attempts to find the URL for the thumbnail size of an image attached to a Post * * @param int $post_id The ID of the WordPress Post * @param string $image_url The URL of the image to get a thumbnail for * * @global $wpdb * * @uses current_theme_supports() * @uses get_the_post_thumbnail() * @uses wpdb::prepare() * @uses wpdb::get_row() * @uses wp_get_attachment_image() * @uses wp_upload_dir() * * @return string */ private function _get_post_thumbnail($post_id, $image_url) { global $wpdb; $thumbnail_src = $image_url; $thumbnail_html = ""; // Use the post thumbnail if possible if (current_theme_supports('post-thumbnails')) { $thumbnail_html = get_the_post_thumbnail($post_id, 'thumbnail'); } // Process for a thumbnail version of the background image $url_parts = parse_url($image_url); // Get array of URL parts of the image $wp_upload_dir = wp_upload_dir(); // Get array of URL parts of the upload directory $relative_upload_base = str_replace(ABSPATH, "", str_replace($wp_upload_dir['subdir'], "", $wp_upload_dir['path'])); if (isset($url_parts['host']) && $url_parts['host'] == $_SERVER['HTTP_HOST'] && strpos($url_parts['path'], "/" . $relative_upload_base) !== false) { $image_url_original = preg_replace("/\\-[0-9]+x[0-9]+\\.(jpeg|jpg|gif|png|bmp)\$/", ".\$1", $image_url); $post = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->posts} WHERE guid = %s", $image_url_original)); if (!empty($post)) { $thumbnail_html = wp_get_attachment_image($post->ID, 'thumbnail'); } } if (!empty($thumbnail_html)) { $matches = array(); preg_match("/ src\\=\"([^\"]+)\"/", $thumbnail_html, $matches); if (count($matches) > 1) { $thumbnail_src = $matches[1]; } } return $thumbnail_src; }
/** * Editor Element - this function defines the visual appearance of an element on the AviaBuilder Canvas * Most common usage is to define some markup in the $params['innerHtml'] which is then inserted into the drag and drop container * Less often used: $params['data'] to add data attributes, $params['class'] to modify the className * * * @param array $params this array holds the default values for $content and $args. * @return $params the return array usually holds an innerHtml key that holds item specific markup. */ function editor_element($params) { $img = ""; $template = $this->update_template("src", "<img src='{{src}}' alt=''/>"); if (!empty($params['args']['attachment']) && !empty($params['args']['attachment_size'])) { $img = wp_get_attachment_image($params['args']['attachment'], $params['args']['attachment_size']); } else { if (isset($params['args']['src']) && is_numeric($params['args']['src'])) { $img = wp_get_attachment_image($params['args']['src'], 'large'); } else { if (!empty($params['args']['src'])) { $img = "<img src='" . $params['args']['src'] . "' alt='' />"; } } } $params['innerHtml'] = "<div class='avia_image avia_hotspot_image avia_image_style '>"; $params['innerHtml'] .= "<div class='avia_image_container avia-align-center ' {$template}>{$img}</div>"; $params['innerHtml'] .= "<div class='avia-flex-element'>"; $params['innerHtml'] .= __('This element will stretch across the whole screen by default.', 'avia_framework') . "<br/>"; $params['innerHtml'] .= __('If you put it inside a color section or column it will only take up the available space', 'avia_framework'); $params['innerHtml'] .= "\t<div class='avia-flex-element-2nd'>" . __('Currently:', 'avia_framework'); $params['innerHtml'] .= "\t<span class='avia-flex-element-stretched'>« " . __('Stretch fullwidth', 'avia_framework') . " »</span>"; $params['innerHtml'] .= "\t<span class='avia-flex-element-content'>| " . __('Adjust to content width', 'avia_framework') . " |</span>"; $params['innerHtml'] .= "\t</div>"; $params['innerHtml'] .= "\t<span class='av_hotspot_image_caption button button-primary button-large'>" . __('Image with Hotspots - Click to insert image and hotspots', 'avia_framework') . "</span>"; $params['innerHtml'] .= "</div>"; $params['innerHtml'] .= "</div>"; $params['class'] = ""; return $params; }
/** * Callback: show the metabox content * * @param $post */ public function add_metabox_content($post) { wp_nonce_field('apg_metabox_nonce', 'apg_metabox_nonce'); $viewer = new Viewer(); $photos = $viewer->get_photos($post->ID); if (count($photos) >= 1) { $photo_hidden = array(); echo '<div style="width: 95%; padding: 0;">'; echo '<ul id="apg-sortable" class="apg-sortable">'; foreach ($photos as $photo) { if (empty($photo['ID'])) { continue; } echo '<li id="apg-photo-' . esc_attr($photo['ID']) . '" data-apgid="' . esc_attr($photo['ID']) . '" style="float: left;width: 80px; height: 80px; display: block; position:relative; border: 1px solid #e5e5e5; background-color: #fff; cursor: move; padding: 0; margin-right: 10px; margin-bottom: 10px;">'; echo '<p style="padding: 3px; margin: 0; display: block;">'; echo wp_get_attachment_image($photo['ID'], 'apg-thumbnail-75-75'); echo '</p>'; echo '<div class="apg-delete-photo" data-apgid="' . esc_attr($photo['ID']) . '" style="cursor: pointer;display:block;position:absolute;top:-5px;margin-left: 67px;width: 16px;height:16px;border-radius:10px;padding:0;padding-top:-4px;border: 2px solid #ccc;font-size: 7px;background-color:#333;color:#fff;text-align:center;">X</div>'; echo '</li>'; $photo_hidden[] = $photo['ID']; } echo '</ul></div><div style="clear: both;"></div>'; echo '<input type="hidden" name="apg_photo_order" id="apg_photo_order" value="' . implode(',', $photo_hidden) . '" />'; echo '<p><i>' . __('If you want to upload new photos to this album, please use the "Upload photo(s)" menu item on the left.', 'apg') . '</i></p>'; } else { echo '<p><strong>' . __('No photos where uploaded, yet. Please use the submenu item "Upload photo(s)" in the menu to upload new photos, or use the button below.', 'apg') . '</strong></p>'; } echo '<p>' . __('You can add or upload new photo\'s into this album on the upload page.', 'apg') . ' <a href="' . admin_url('edit.php?post_type=apg_photo_albums&page=apg_upload') . '" class="button">' . __('Add new Photo\'s', 'apg') . '</a></p>'; }
function shortcode_ui_dev_shortcode($attr, $content = '') { //Parse the attribute of the shortcode $attr = wp_parse_args($attr, array('source' => '', 'attachment' => 0)); ob_start(); ?> <section class="pullquote" style="padding: 20px; background: rgba(0,0,0,0.1);"> <p style="margin:0; padding: 0;"> <b>Content:</b> <?php echo wpautop(wp_kses_post($content)); ?> </br> <b>Source:</b> <?php echo esc_html($attr['source']); ?> </br> <b>Image:</b> <?php echo wp_kses_post(wp_get_attachment_image($attr['attachment'], array(50, 50))); ?> </br> </p> </section> <?php return ob_get_clean(); }
/** * Gallery OptionType */ function spyropress_ui_gallery($item, $id, $value, $is_widget = false, $is_builder = false) { ob_start(); // collecting attributes $atts = array(); $atts['class'] = 'gallery_shortcode' . ($value != '' ? ' has-file' : ''); $atts['type'] = 'hidden'; $atts['id'] = esc_attr($id); $atts['name'] = esc_attr($item['name']); $atts['value'] = esc_attr($value); $ids = explode(',', $value); echo '<div ' . build_section_class('section-gallery section-full', $item) . '>'; printf('<input class="gallery_reset_button button-red button-large pull-right" type="button" value="%s" /> ', __('Clear Gallery', 'spyropress')); printf('<input class="gallery_upload_button button button-primary button-large right" type="button" value="%2$s" id="upload_%1$s" />', $id, __('Add/Edit Gallery', 'spyropress')); build_heading($item, $is_widget); build_description($item); echo '<div class="controls">'; echo '<div class="gallery_holder clearfix">'; foreach ($ids as $id) { printf('<div data-id="%1$s" class="gallery-item">%2$s</div>', $id, wp_get_attachment_image($id)); } echo '</div>'; printf('<input%s />', spyropress_build_atts($atts)); echo '</div>'; echo '</div>'; $ui_content = ob_get_clean(); if ($is_widget) { return $ui_content; } else { echo $ui_content; } }
function portfolio_column_display($portfolio_columns, $post_id) { // Code from: http://wpengineer.com/display-post-thumbnail-post-page-overview switch ($portfolio_columns) { // Display the thumbnail in the column view case "thumbnail": $width = (int) 35; $height = (int) 35; $thumbnail_id = get_post_meta($post_id, '_thumbnail_id', true); // Display the featured image in the column view if possible if ($thumbnail_id) { $thumb = wp_get_attachment_image($thumbnail_id, array($width, $height), true); } if (isset($thumb)) { echo $thumb; } else { echo __('None', 'portfolioposttype'); } break; // Display the portfolio tags in the column view // Display the portfolio tags in the column view case "portfolio_filter": if ($category_list = get_the_term_list($post_id, 'portfolio_filter', '', ', ', '')) { echo $category_list; } else { echo __('None', 'portfolioposttype'); } break; } }
function wm_logo() { //Helper variables $output = ''; $blog_info = apply_filters('wmhook_wm_logo_blog_info', array('name' => trim(get_bloginfo('name')), 'description' => trim(get_bloginfo('description')))); $args = apply_filters('wmhook_wm_logo_args', array('title_att' => $blog_info['description'] ? $blog_info['name'] . ' | ' . $blog_info['description'] : $blog_info['name'], 'logo_image' => function_exists('jetpack_get_site_logo') ? absint(jetpack_get_site_logo('id')) : false, 'logo_type' => 'text', 'url' => home_url('/'))); //Preparing output //Logo image if (!empty($args['logo_image'])) { $img_id = is_numeric($args['logo_image']) ? absint($args['logo_image']) : wm_get_image_id_from_url($args['logo_image']); if ($img_id) { $logo_url = wp_get_attachment_image_src($img_id, 'full'); $atts = (array) apply_filters('wmhook_wm_logo_image_atts', array('alt' => esc_attr(sprintf(_x('%s logo', 'Site logo image "alt" HTML attribute text.', 'wm_domain'), $blog_info['name'])), 'title' => esc_attr($args['title_att']), 'class' => '')); $args['logo_image'] = wp_get_attachment_image($img_id, 'full', false, $atts); } $args['logo_type'] = 'img'; } $args['logo_image'] = apply_filters('wmhook_wm_logo_logo_image', $args['logo_image']); //Logo HTML $output .= '<div class="site-branding">'; $output .= '<h1 class="' . apply_filters('wmhook_wm_logo_class', 'site-title logo type-' . $args['logo_type'], $args) . '">'; $output .= '<a href="' . esc_url($args['url']) . '" title="' . esc_attr($args['title_att']) . '">'; if ('text' === $args['logo_type']) { $output .= '<span class="text-logo">' . $blog_info['name'] . '</span>'; } else { $output .= $args['logo_image']; } $output .= '</a></h1>'; if ($blog_info['description']) { $output .= '<h2 class="site-description">' . $blog_info['description'] . '</h2>'; } $output .= '</div>'; //Output echo apply_filters('wmhook_wm_logo_output', $output); }
/** * Display the logo or site title */ function siteorigin_north_display_logo() { $logo = siteorigin_setting('branding_logo'); if (!empty($logo)) { $logo_id = attachment_url_to_postid($logo); $attrs = apply_filters('siteorigin_north_logo_attributes', array()); ?> <a href="<?php echo esc_url(home_url('/')); ?> " rel="home"><?php echo wp_get_attachment_image($logo_id, 'full', false, $attrs); ?> </a><?php } else { ?> <h1 class="site-title"><a href="<?php echo esc_url(home_url('/')); ?> " rel="home"><?php bloginfo('name'); ?> </a></h1><?php } }
function dtwl_woo_get_product_first_thumbnail($size = 'shop_catalog', $deprecated1 = 0, $deprecated2 = 0) { global $post, $product; $html = ''; $attachment_ids = $product->get_gallery_attachment_ids(); $i = 0; if ($attachment_ids) { $i++; foreach ($attachment_ids as $attachment_id) { $image_link = wp_get_attachment_url($attachment_id); if (!$image_link) { continue; } $image_title = esc_attr(get_the_title($attachment_id)); $image = wp_get_attachment_image($attachment_id, apply_filters('single_product_small_thumbnail_size', $size), 0, $attr = array('title' => $image_title, 'alt' => $image_title)); $html = '<div class="dtwl-woo-product-thumbnail dtwl-woo-product-back-thumbnail">'; $html .= $image; $html .= '</div>'; if ($i == 1) { break; } } } return $html; }
public function get($type = "", $id = "", $size = "", $attr = array()) { if (is_array($id) && $id["id"]) { $id = $id["id"]; } if (!$id) { $id = get_post_thumbnail_id(get_the_ID()); } if (!$id) { $id = get_field('image', get_the_ID()); $id = $id["id"]; } if (!$id) { $id = get_field('placeholder', 'options'); } if (!$id) { return; } if ($type == "html") { return wp_get_attachment_image($id, $size); } else { if ($type == "url") { return reset(wp_get_attachment_image_src($id, $size)); } else { if ($type == "") { return wp_get_attachment_metadata($id); } else { $res = wp_get_attachment_metadata($id); return $res[$type]; } } } }
/** * Return the HTML output for first image found for a post. * * @param int post_id ID for parent post * @param string the_content * @param string before Optional before string * @param string after Optional after string * @return boolean|string HTML output or false if no match */ function esquire_image_grabber( $post_id, $the_content = '', $before = '', $after = '' ) { global $wpdb; $image_src = ''; if ( empty( $the_content ) ) $the_content = get_the_content(); $first_image = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'attachment' AND INSTR(post_mime_type, 'image') ORDER BY menu_order ASC LIMIT 0,1", (int) $post_id ) ); if ( ! empty( $first_image ) ) { // We have an attachment, so just use its data. $image_src = wp_get_attachment_image( $first_image, 'image' ); } else { // Try to get the image for the linked image (not attached) $output = preg_match( WPCOM_THEMES_IMAGE_REGEX, $the_content, $matches ); if ( isset( $matches[0] ) ) $image_src = $matches[0]; } if ( ! empty( $image_src ) ) { // Add wrapper markup, if specified if ( ! empty( $before ) ) $image_src = $before . $image_src; if ( ! empty( $after ) ) $image_src = $image_src . $after; return $image_src; } return false; }
/** * Form data for post edit page. * * @param type $field */ function wpcf_fields_file_meta_box_form($field, $image = false) { add_thickbox(); $type = $image ? 'image' : 'file'; $button_text = $image ? __('Upload image', 'wpcf') : __('Upload file', 'wpcf'); // Get attachment by guid global $wpdb; $attachment_id = $wpdb->get_var($wpdb->prepare("SELECT ID FROM {$wpdb->posts}\r\r\n WHERE post_type = 'attachment' AND guid=%s", $field['value'])); // Set preview $preview = ''; if (!empty($attachment_id)) { $preview = wp_get_attachment_image($attachment_id, 'thumbnail'); } else { // If external image set preview $file = pathinfo($field['value']); if (isset($file['extension']) && in_array($file['extension'], array('jpg', 'jpeg', 'gif', 'png'))) { $preview = '<img alt="" src="' . $field['value'] . '" />'; } } // Set button if (!empty($field['#attributes']['readonly']) || !empty($field['#attributes']['disabled'])) { $button = ''; } else { $button = '<a href="javascript:void(0);"' . ' class="wpcf-fields-' . $type . '-upload-link button-secondary"' . ' id="wpcf-fields-' . $field['slug'] . '-upload">' . $button_text . '</a>'; } // Set form $form = array('#type' => 'textfield', '#id' => 'wpcf-fields-' . $field['slug'] . '-upload-holder', '#name' => 'wpcf[' . $field['slug'] . ']', '#suffix' => ' ' . $button, '#after' => '<div id="wpcf-fields-' . $field['slug'] . '-upload-holder-preview"' . ' class="wpcf-fields-file-preview">' . $preview . '</div>', '#attributes' => array('class' => 'wpcf-fields-file-textfield')); return $form; }
function upload_file($image_only = false) { $upload = array('name' => $_FILES['wpuf_file']['name'], 'type' => $_FILES['wpuf_file']['type'], 'tmp_name' => $_FILES['wpuf_file']['tmp_name'], 'error' => $_FILES['wpuf_file']['error'], 'size' => $_FILES['wpuf_file']['size']); header('Content-Type: text/html; charset=' . get_option('blog_charset')); $attach = $this->handle_upload($upload); if ($attach['success']) { $response = array('success' => true); if ($image_only) { $image_size = wpuf_get_option('insert_photo_size', 'wpuf_general', 'thumbnail'); $image_type = wpuf_get_option('insert_photo_type', 'wpuf_general', 'link'); if ($image_type == 'link') { $response['html'] = wp_get_attachment_link($attach['attach_id'], $image_size); } else { $response['html'] = wp_get_attachment_image($attach['attach_id'], $image_size); } } else { $response['html'] = $this->attach_html($attach['attach_id']); } echo $response['html']; } else { echo 'error'; } // $response = array('success' => false, 'message' => $attach['error']); // echo json_encode( $response ); exit; }