Пример #1
0
/**
 * Helper function to grab and display thumbnail from specified post
 * @since 1.4.0
 */
function arras_get_thumbnail($size = 'thumbnail', $id = NULL)
{
    global $post, $arras_image_sizes;
    $empty_thumbnail = '<img src="' . get_template_directory_uri() . '/images/thumbnail.png" alt="' . get_the_excerpt() . '" title="' . get_the_title() . '" />';
    if ($post) {
        $id = $post->ID;
    }
    // get post thumbnail (WordPress 2.9)
    if (function_exists('has_post_thumbnail')) {
        if (has_post_thumbnail($id)) {
            return get_the_post_thumbnail($id, $size, array('alt' => get_the_excerpt(), 'title' => get_the_title()));
        } else {
            // Could it be an attachment?
            if ($post->post_type == 'attachment') {
                return wp_get_attachment_image($id, $size, false, array('alt' => get_the_excerpt(), 'title' => get_the_title()));
            }
            // Use first thumbnail if auto thumbs is enabled.
            if (arras_get_option('auto_thumbs')) {
                $img_id = arras_get_first_post_image_id();
                if (!$img_id) {
                    return $empty_thumbnail;
                }
                return wp_get_attachment_image($img_id, $size, false, array('alt' => get_the_excerpt(), 'title' => get_the_title()));
            }
        }
    }
    return $empty_thumbnail;
}
Пример #2
0
/**
 * Helper function to grab and display thumbnail from specified post
 * @since 1.4.0
 */
function arras_get_thumbnail($size = 'thumbnail', $id = NULL)
{
    global $post, $arras_image_sizes;
    $empty_thumbnail = '<img src="' . get_bloginfo('template_directory') . '/images/thumbnail.png" alt="' . get_the_excerpt() . '" title="' . get_the_title() . '" />';
    if ($post) {
        $id = $post->ID;
    }
    // get post thumbnail (WordPress 2.9)
    if (function_exists('has_post_thumbnail')) {
        if (has_post_thumbnail($id)) {
            return get_the_post_thumbnail($id, $size, array('alt' => get_the_excerpt(), 'title' => get_the_title()));
        } else {
            if (arras_get_option('auto_thumbs')) {
                $img_id = arras_get_first_post_image_id();
                if (!$img_id) {
                    return $empty_thumbnail;
                }
                return wp_get_attachment_image($img_id, $size, false, array('alt' => get_the_excerpt(), 'title' => get_the_title()));
            }
        }
    }
    // go back to legacy (phpThumb or timThumb)
    $thumbnail = get_post_meta($id, ARRAS_POST_THUMBNAIL, true);
    $w = $arras_image_sizes[$size]['w'];
    $h = $arras_image_sizes[$size]['h'];
    if ($thumbnail != '') {
        if (!$arras_image_sizes[$size]) {
            return false;
        }
        return '<img src="' . get_bloginfo('template_directory') . '/library/timthumb.php?src=' . $thumbnail . '&amp;w=' . $w . '&amp;h=' . $h . '&amp;zc=1" alt="' . get_the_excerpt() . '" title="' . get_the_title() . '" />';
    } else {
        if (arras_get_option('auto_thumbs')) {
            if (!$arras_image_sizes[$size]) {
                return false;
            }
            $img_id = arras_get_first_post_image_id();
            if (!$img_id) {
                return $empty_thumbnail;
            }
            $image = wp_get_attachment_image_src($img_id, 'full', false);
            if ($image) {
                list($src, $width, $height) = $image;
                return '<img src="' . get_bloginfo('template_directory') . '/library/timthumb.php?src=' . $src . '&amp;w=' . $w . '&amp;h=' . $h . '&amp;zc=1" alt="' . get_the_excerpt() . '" title="' . get_the_title() . '" />';
            }
        }
    }
    return $empty_thumbnail;
}
Пример #3
0
function arras_add_facebook_share_meta()
{
    global $post;
    if (is_single()) {
        if (has_post_thumbnail($post->ID)) {
            $thumb_id = get_post_thumbnail_id($post->ID);
        } elseif (arras_get_option('auto_thumbs')) {
            $thumb_id = arras_get_first_post_image_id();
        }
        if (!$thumb_id) {
            return false;
        }
        $image = wp_get_attachment_image_src($thumb_id);
        $src = $image[0];
        ?>
	<meta property="og:title" content="<?php 
        echo get_the_title($post->ID);
        ?>
" />
	<meta property="og:description" content="<?php 
        echo get_the_excerpt();
        ?>
" />
	<meta property="og:image" content="<?php 
        echo $image[0];
        ?>
" />
	<?php 
    }
}