예제 #1
0
function wpa_slideshow_from_gallery($output, $attr)
{
    if (isset($attr['wpa_slideshow'])) {
        global $post, $wp_locale;
        static $instance = 0;
        $instance++;
        $size = isset($attr['size']) ? $attr['size'] : 'thumbnail';
        $attachments = explode(',', $attr['ids']);
        $output = apply_filters('gallery_style', "");
        $i = 0;
        $output .= '<div id="wpa-slideshow-' . $instance . '" class="wpa_slideshow swiper-container"><div class="swiper-wrapper">';
        foreach ($attachments as $id) {
            if (isset($attr['link']) && 'none' === $attr['link']) {
                $link = '<img src="' . image_src($id, $size) . '" alt="' . get_alt($id) . '" />';
            } elseif (isset($attr['link']) && 'file' === $attr['link']) {
                $link = wp_get_attachment_link($id, $size, false, false);
                $pic_link = str_replace('href="', 'target="_blank" href="', $link);
            } else {
                $link = wp_get_attachment_link($id, $size, true, false);
                $pic_link = str_replace('href="', 'target="_blank" href="', $link);
            }
            $pic_link = str_replace(wp_get_attachment_image_src($id, 'full', false), wp_get_attachment_image_src($id, 'large', false), $link);
            $pic_link = str_replace('src="', 'class="swiper-lazy" data-src="', $pic_link);
            $output .= '<div class="swiper-slide">';
            $output .= $pic_link;
            $output .= '<div class="swiper-lazy-preloader"></div></div>';
        }
        $output .= '</div><div class="swiper-pagination"></div><div class="swiper-button-prev"></div><div class="swiper-button-next"></div></div>';
    }
    return $output;
}
예제 #2
0
 function woocommerce_get_product_thumbnail($size = 'large', $placeholder_width = 0, $placeholder_height = 0)
 {
     global $post, $woocommerce;
     $output = '';
     if (has_post_thumbnail()) {
         $output .= get_the_post_thumbnail($post->ID, $size);
     } else {
         $output .= '<img src="' . woocommerce_placeholder_img_src() . '" alt="' . get_alt($post->ID) . '" />';
     }
     return $output;
 }
예제 #3
0
        $classes .= ' ' . $cat->slug;
    }
}
?>
<div class="grid-item<?php 
echo $product->is_on_sale() ? ' sale' : '';
echo $classes;
?>
">
    <?php 
$thumbnal_id = get_post_thumbnail_id($product->id);
$img = wp_get_attachment_image_src($thumbnal_id, 'shop_catalog', true);
echo '<a class="product-image" href="' . get_permalink($product->id) . '">';
woocommerce_show_product_loop_sale_flash();
if (has_post_thumbnail($product->id)) {
    echo '<img src="' . placeImg($img[1], $img[2]) . '" alt="' . get_alt($thumbnal_id) . '" data-defer="' . $img[0] . '" class="aligncenter" width="' . $img[1] . '" height="' . $img[2] . '" />';
} else {
    echo wc_placeholder_img('shop_catalog');
}
echo '</a>';
?>
    <div class="product-data">
        <a class="product-title" href="<?php 
the_permalink();
?>
">
            <h3><?php 
echo get_the_title($product->id);
?>
</h3>
            <div class="product-price"><?php 
예제 #4
0
        ?>
 </small>
					</header>
					<?php 
        if (isset($feat) && !empty($feat)) {
            ?>
						<div class="row">
							<div class="col-md-4">
								<a href="<?php 
            echo the_permalink();
            ?>
"><img class="img-responsive center-block thumbnail" src="<?php 
            echo $feat;
            ?>
" alt="<?php 
            echo get_alt(get_post_thumbnail_id());
            ?>
" /></a>
							</div>
							<div class="col-md-8">
								<?php 
            the_excerpt('Read the rest of this entry &raquo;');
            ?>
							</div>
						</div>
					<?php 
        } else {
            ?>
							<?php 
            the_excerpt('Read the rest of this entry &raquo;');
            ?>
function the_attached_image($args = '')
{
    global $post;
    parse_str($args);
    //Tenutive support for the old options method. Please use the options page, it's much neater.
    if (!isset($img_size) && !get_option('att_img_size')) {
        $img_size = 'thumbnail';
    } elseif (isset($img_size)) {
        $img_size = $img_size;
    } else {
        $img_size = get_option('att_img_size');
    }
    if (!isset($css_class) && !get_option('att_css_class')) {
        $css_class = 'attached-image';
    } elseif (isset($css_class)) {
        $css_class = $css_class;
    } else {
        $css_class = get_option('att_css_class');
    }
    if (!isset($img_tag) && !get_option('att_img_tag')) {
        $img_tag = true;
    } elseif (isset($img_tag)) {
        $img_tag = $img_tag;
    } else {
        $img_tag = get_option('att_img_tag');
    }
    if (!isset($echo) && !get_option('att_echo')) {
        $echo = true;
    } elseif (isset($echo)) {
        $echo = $echo;
    } else {
        $echo = get_option('att_echo');
    }
    if (!isset($href)) {
        $href = false;
    }
    if (!isset($link) && !get_option('att_href')) {
        $link = 'none';
    } elseif (isset($link)) {
        $link = $link;
        if ($link != 'none') {
            $href = true;
        } else {
            $href = false;
        }
    } else {
        $link = get_option('att_href');
        if ($link != 'none') {
            $href = true;
        } else {
            $href = false;
        }
        if (get_post_meta($post->ID, 'att_custom_link', true) != "") {
            $href = true;
            $link = "custom";
            //override the link to custom because the custom field is set.
        }
    }
    if (!isset($alt) && !get_option('att_alt')) {
        $alt = 'image-name';
    } elseif (isset($alt)) {
        $alt = $alt;
    } else {
        if (get_post_meta($post->ID, 'att_custom_alt', true)) {
            $alt = 'custom';
        } else {
            $alt = get_option('att_alt');
        }
    }
    if (!isset($link_title) && !get_option('att_link_title')) {
        $link_title = 'image-name';
    } elseif (isset($link_title)) {
        $link_title = $link_title;
    } else {
        if (get_post_meta($post->ID, 'att_custom_link_title', true)) {
            $link_title = 'custom';
        } else {
            $link_title = get_option('att_link_title');
        }
    }
    if (!isset($default) && !get_option('att_default_img')) {
        $default = false;
    } elseif (isset($default)) {
        $default = $default;
    } else {
        $default = get_option('att_default_img');
    }
    if (!isset($width) && !get_option('att_img_width')) {
        $width = false;
    } elseif (isset($width)) {
        $width = $width;
    } else {
        $width = get_option('att_img_width');
    }
    if (!isset($height) && !get_option('att_img_height')) {
        $height = false;
    } elseif (isset($height)) {
        $height = $height;
    } else {
        $height = get_option('att_img_height');
    }
    if (!isset($image_order) && !get_option('att_img_order')) {
        $image_order = 1;
    } elseif (isset($image_order)) {
        if (is_numeric($image_order)) {
            $image_order = intval($image_order);
        } else {
            $image_order = 1;
        }
    } else {
        $image_order = get_option('att_img_order');
        if (is_numeric($image_order)) {
            $image_order = intval($image_order);
        } else {
            $image_order = 1;
        }
    }
    if (!isset($rel) && !get_option('att_href_rel')) {
        $rel = false;
    } elseif (isset($rel)) {
        $rel = $rel;
    } else {
        $rel = get_option('att_href_rel');
    }
    if ($custom_img_meta = get_post_meta($post->ID, 'att_custom_img', true)) {
        $attachments = array(get_post($custom_img_meta));
        $custom_img = true;
    } else {
        $custom_img = false;
    }
    //If WP's post array is empty we can't do anything but only if a custom image hasn't been set.
    if (empty($post) && $custom_img === false && get_post_meta($post->ID, 'att_default_pic', true) == "") {
        return false;
    }
    if ($custom_img === false) {
        //Get the attachments for the current post. Limit to one and order by the menu_order so that the image shown can be changed by the WP gallery.
        if (function_exists('wp_enqueue_style')) {
            $attachments = get_children(array('post_parent' => $post->ID, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID'));
        } else {
            //WP2.5 Compat...
            $attachments = get_children('post_parent=' . $post->ID . '&post_type=attachment&post_mime_type=image&orderby="menu_order ASC, ID ASC"');
        }
    }
    $m_width = get_post_meta($post->ID, 'att_width', true);
    $m_height = get_post_meta($post->ID, 'att_height', true);
    if (!$width === false && !$m_width == false && !$height === false) {
        $width = $m_width;
        $height = false;
    } elseif (!$height === false && !$m_height == false && !$width === false) {
        $height = $m_height;
        $width = false;
    } else {
        $width = !$m_width == false ? $m_width : $width;
        $height = !$m_height == false ? $m_height : $height;
    }
    // ^^ Check for custom fields. To stop function call follow through we need to cancel out the $width or the $height if only one has been set by meta.
    if (empty($attachments)) {
        //If attachments is empty then we should check for a default image via meta or via function call.
        if ($pic_meta = get_post_meta($post->ID, 'att_default_pic', true)) {
            $default = $pic_meta;
        } elseif ($default === false) {
            return false;
        }
        $image = '<img src="' . esc_url(get_bloginfo('url') . $default) . '" class="' . esc_attr($css_class) . '" ';
        //get the alt text
        $alt_text = get_alt($alt);
        if (!empty($alt_text)) {
            $image .= 'alt="' . esc_attr($alt_text) . '" ';
        }
        if (stristr($link, 'post') === false && stristr($link, 'custom') === false) {
            //get the title text
            $img_title_text = get_title($link_title);
            $image .= 'title="' . esc_attr($img_title_text) . '" ';
        }
        if ($height === false && $width === false) {
            //Sort out the height & width depending on what has been supplied by the user.
            //Get the image size using ABSPATH. Suppresion of errors via @ is not expensive despite what you have heard. It's the generation of the error.
            $default_info = @getimagesize(substr(ABSPATH, 0, -1) . $default);
            $image .= !empty($default_info[3]) ? $default_info[3] . ' />' : ' />';
        } else {
            if (!$width === false && !$height === false) {
                $image .= 'width="' . esc_attr($width) . '" height="' . esc_attr($height) . '" />';
            } elseif (!$width === false) {
                $image .= 'width="' . esc_attr($width) . '" />';
            } elseif (!$height === false) {
                $image .= 'height="' . esc_attr($height) . '" />';
            }
        }
        if ($href === true || $href == 'true') {
            //Do you want a href & where should it point.
            switch ($link) {
                case 'post':
                    $a_href = '<a href="' . esc_url(get_permalink($post->ID)) . '" title="' . esc_attr($post->post_title) . '">%%%</a>';
                    break;
                case 'custom':
                    $link_meta = get_post_meta($post->ID, 'att_custom_link', true);
                    //no need to check since it wouldn't be here if it were empty.
                    $a_href = '<a href="' . esc_url($link_meta) . '">%%%</a>';
                    break;
            }
        }
        if (isset($a_href) && !empty($a_href)) {
            //If they wanted a link put the img tag into it.
            $image = str_replace('%%%', $image, $a_href);
        }
    }
    if (!isset($image) && empty($image)) {
        //Gets the correct image depending upon whether or not $image has been set or not.
        $i = 0;
        foreach ($attachments as $id => $attachment) {
            $i++;
            if ($i == $image_order) {
                $attachment = $attachment;
                break;
            }
        }
        //$attachment = current($attachments);
        $img_url = wp_get_attachment_url($attachment->ID);
        //Get URL to attachment
        //Pick the right size & get it via WP. If a custom height & width was set cancel out WP's.
        if (in_array($img_size, array('thumbnail', 'medium', 'large'))) {
            if ($intermediate = image_downsize($attachment->ID, $img_size)) {
                $img_url = $intermediate[0];
                if ($width === false && $height === false) {
                    $width = $intermediate[1];
                    $height = $intermediate[2];
                }
            }
        } elseif ($img_size == 'full') {
            //Get the image's size since it will make our HTML invalid & the code won't close the img tag without a width & height.
            $split_pos = strpos($img_url, 'wp-content');
            $split_len = strlen($img_url) - $split_pos;
            $abs_img_url = substr($img_url, $split_pos, $split_len);
            $full_info = @getimagesize(ABSPATH . $abs_img_url);
            if ($width === false && $height === false) {
                $width = $full_info[0];
                $height = $full_info[1];
            }
        }
        if ($img_tag === true || $img_tag == 'true') {
            //Do they want an image tag along with setting the height & width.
            $image = '<img src="' . esc_url($img_url) . '" class="' . esc_attr($css_class) . '"';
            $alt_text = get_alt($alt);
            //Get alt text
            if (!empty($alt_text)) {
                $image .= ' alt="' . esc_attr($alt_text) . '"';
            }
            if (stristr($link, 'none')) {
                $title_text = get_title($link_title);
                $image .= ' title="' . esc_attr($title_text) . '"';
            }
            if (!$width === false && !$height === false) {
                $image .= ' width="' . esc_attr($width) . '" height="' . esc_attr($height) . '" />';
            } elseif (!$width === false) {
                $image .= ' width="' . esc_attr($width) . '" />';
            } elseif (!$height === false) {
                $image .= ' height="' . esc_attr($height) . '" />';
            } else {
                $image .= ' />';
            }
        } else {
            //You don't want a img tag then? Well heres the URL.
            $image = $img_url;
        }
        if ($href === true || $href == 'true') {
            //Do you want a href & where should it point.
            //First lets figure out what title text they want...
            $a_title_text = get_title($link_title);
            switch ($link) {
                case 'post':
                    $a_href = '<a href="' . esc_url(get_permalink($post->ID)) . '" title="' . esc_attr($a_title_text) . '">%%%</a>';
                    break;
                case 'attachment':
                    $a_href = '<a href="' . esc_url(get_attachment_link($attachment->ID)) . '" title="' . esc_attr($a_title_text) . '">%%%</a>';
                    break;
                case 'custom':
                    $link_meta = get_post_meta($post->ID, 'att_custom_link', true);
                    //no need to check since it wouldn't be here if it were empty.
                    $a_href = '<a href="' . esc_url($link_meta) . '" title="' . esc_attr($a_title_text) . '">%%%</a>';
                    break;
                default:
                    if (!$rel === false) {
                        $a_href = '<a href="' . esc_url(wp_get_attachment_url($attachment->ID)) . '" rel="' . esc_attr($rel) . '" title="' . esc_attr($a_title_text) . '">%%%</a>';
                    } else {
                        $a_href = '<a href="' . esc_url(wp_get_attachment_url($attachment->ID)) . '" title="' . esc_attr($a_title_text) . '">%%%</a>';
                    }
                    break;
            }
        }
        if (isset($a_href) && !empty($a_href)) {
            //If they wanted a link put the img tag into it.
            $image = str_replace('%%%', $image, $a_href);
        }
    }
    if ($echo === true || $echo == 'true') {
        //Echo it?
        echo $image;
    } else {
        //Ok we'll return it instead.
        return $image;
    }
}
예제 #6
0
function create_default_image($link, $link_title, $width, $height, $href, $post, $default, $css_class, $alt, $img_tag)
{
    if ($pic_meta = get_post_meta($post->ID, 'att_default_pic', true)) {
        $default = $pic_meta;
    } elseif ($default === false) {
        return false;
    }
    // Thanks to Eduardo Gonzalez for the bug report & fix. Fix needs a little modification due to unforseen bug.
    if ($img_tag === true || $img_tag == 'true') {
        //Do they want an image tag along with setting the height & width.
        $image = '<img src="' . get_bloginfo('url') . $default . '" class="' . $css_class . '" ';
    } else {
        $image = get_bloginfo('url') . $default;
        return $image;
    }
    // End of fix
    //get the alt text
    $attachment = '';
    $alt_text = get_alt($alt, $attachment, $default);
    if (!empty($alt_text)) {
        $image .= 'alt="' . $alt_text . '" ';
    }
    if (stristr($link, 'post') === false && stristr($link, 'custom') === false) {
        //get the title text
        $img_title_text = get_title($link_title, $attachment, $default);
        if (!empty($title_text)) {
            $image .= 'title="' . $img_title_text . '" ';
        }
    }
    if ($height === false && $width === false) {
        //Sort out the height & width depending on what has been supplied by the user.
        //Get the image size using ABSPATH. Suppresion of errors via @ is not expensive despite what you have heard. It's the generation of the error.
        $default_info = @getimagesize(substr(ABSPATH, 0, -1) . $default);
        $image .= !empty($default_info[3]) ? $default_info[3] . ' />' : ' />';
    } else {
        if (!$width === false && !$height === false) {
            $image .= 'width="' . $width . '" height="' . $height . '" />';
        } elseif (!$width === false) {
            $image .= 'width="' . $width . '" />';
        } elseif (!$height === false) {
            $image .= 'height="' . $height . '" />';
        }
    }
    if ($href === true || $href == 'true') {
        //Do you want a href & where should it point.
        switch ($link) {
            case 'post':
                $a_href = '<a href="' . get_permalink($post->ID) . '" title="' . $post->post_title . '">%%%</a>';
                break;
            case 'custom':
                $link_meta = get_post_meta($post->ID, 'att_custom_link', true);
                //no need to check since it wouldn't be here if it were empty.
                $a_href = '<a href="' . $link_meta . '">%%%</a>';
                break;
        }
    }
    if (isset($a_href) && !empty($a_href)) {
        //If they wanted a link put the img tag into it.
        $image = str_replace('%%%', $image, $a_href);
    }
    return $image;
}