Выводим последнее изображение, привязанное к записи
Вместо того чтобы возиться с URL изображений, можно использовать короткий код, который возвращает и выводит последнее изображение, привязанное к записи. Скопируйте ниже приведенный код в файл functions.php вашей темы:
function cwc_postimage($atts, $content = null) {
extract(shortcode_atts(array(
"size" => 'thumbnail',
"float" => 'none'
), $atts));
$images =& get_children( 'post_type=attachment&post_mime_type=image&post_parent=' . get_the_id() );
foreach( $images as $imageID => $imagePost )
$fullimage = wp_get_attachment_image($imageID, $size, false);
$imagedata = wp_get_attachment_image_src($imageID, $size, false);
$width = ($imagedata[1]+2);
$height = ($imagedata[2]+2);
return '<div class="postimage" style="width: '.$width.'px; height: '.$height.'px; float: '.$float.';">'.$fullimage.'</div>';
}
add_shortcode("postimage", "cwc_postimage");
Теперь можно вывести последнее изображение с помощью короткого кода:
[postimage]
Комментарии:
Нету комментариев для вывода...