コード例 #1
0
            foreach ($photos as $photo) {
                $full = wp_get_attachment_image_src($photo['ID'], 'full');
                $thumb = wp_get_attachment_image_src($photo['ID'], 'thumbnail');
                if (!$full || !$thumb) {
                    continue;
                }
                ?>
										<div class="gallery-item">
											<a href="<?php 
                echo esc_attr($full[0]);
                ?>
" class="lightbox-image"><img src="<?php 
                echo esc_attr($thumb[0]);
                ?>
" alt="<?php 
                echo esc_attr(smart_media_alt($thumb[0]));
                ?>
" width="<?php 
                echo esc_attr($thumb[1]);
                ?>
" height="<?php 
                echo esc_attr($thumb[2]);
                ?>
"></a>
										</div>
										<?php 
            }
            ?>
								</div>
								<?php 
        }
コード例 #2
0
?>
<div class="header-image-wrap <?php 
echo $header_image ? 'has-header-image' : 'no-header-image';
?>
">

	<?php 
if ($header_image) {
    ?>
	<div class="header-image">
		<div class="inside">
			<img src="<?php 
    echo esc_attr($header_image);
    ?>
" alt="<?php 
    echo esc_attr(smart_media_alt($header_image));
    ?>
">
		</div>
	</div>
	<?php 
}
?>


	<div class="layout-row has-sidebar clearfix">
		<div class="inside">

			<div id="main">

				<article id="<?php 
コード例 #3
0
function smart_media_array($image_url, $size = 'full', $fallback_to_full = true)
{
    $result = array('id' => '', 'ID' => '', 'sizes' => array(), 'alt' => '', 'real_alt' => '', 'title' => '', 'description' => '', 'caption' => '', 'size' => '', 'url' => '', 'file' => '', 'path' => '', 'width' => '', 'height' => '');
    $result['id'] = smart_media_id($image_url);
    $result['ID'] =& $result['id'];
    //  alias of id
    $attachment = wp_get_attachment_metadata($result['id']);
    if (!$attachment) {
        return false;
    }
    $upload_dir = wp_upload_dir();
    $result['sizes'] = $attachment['sizes'];
    // "Full" doesn't get put in the sizes, but that's where we want it with this function.
    $result['sizes']['full'] = array('file' => $attachment['file'], 'width' => $attachment['width'], 'height' => $attachment['height'], 'mime-type' => 'image/' . pathinfo($attachment['file'], PATHINFO_EXTENSION));
    foreach ($result['sizes'] as $key => $img) {
        $result['sizes'][$key]['path'] = trailingslashit($upload_dir['basedir']) . $img['file'];
        $result['sizes'][$key]['url'] = trailingslashit($upload_dir['baseurl']) . $img['file'];
    }
    // Check for the requested size, if not set, fall back to full size
    if (!isset($result['sizes'][$size])) {
        if (!$fallback_to_full) {
            return false;
        }
        $size = 'full';
    }
    // Requested image size info
    $result['size'] = $size;
    $result['width'] = $result['sizes'][$size]['width'];
    $result['height'] = $result['sizes'][$size]['height'];
    $result['file'] = $result['sizes'][$size]['file'];
    $result['path'] = trailingslashit($upload_dir['basedir']) . $result['file'];
    $result['url'] = trailingslashit($upload_dir['baseurl']) . $result['file'];
    // The optimal alt tag. If the real alt tag is missing, this will infer the title, description, caption or filename to get one.
    $result['alt'] = smart_media_alt(trailingslashit($upload_dir['baseurl']) . $attachment['file']);
    $post = get_post($result['id']);
    if ($post) {
        // Return the actual alt tag, even if it is blank
        $result['real_alt'] = get_post_meta($result['id'], '_wp_attachment_image_alt', true);
        // The rest of the image metadata
        $result['title'] = $post->post_title;
        $result['description'] = $post->post_content;
        $result['caption'] = $post->post_excerpt;
    }
    return $result;
}