Вывод всех привязанных картинок в теле поста

Вопрос такой, к каждой странице привязаны по 3 – 4 картинки. Нужно сделать так, что-бы их превьюшки автоматически выводились в теле поста, в определённом шаблоном месте.

Кто нибудь знает как можно такое сделать?

Почти разобрался, применил плагин Post Image http://guff.szub.net/2006/02/09/post-image/, далее немного подправил его добавив функцию post_image_multiple() :

function post_image_multiple($default_image='', $use_thumb=true, $img_tag=tue, $css_class='post-image', $customkey='post-image', $display=true) {
global $post, $posts, $wp_version, $wpdb;
global $post_image_attachments;
if( empty($post) )
return;
if( !empty($posts) ) {
foreach($posts as $apost) {
if( $posts[0] != $apost )
$IN_ids .= ',';
$IN_ids .= (int) $apost->ID;
}
}

$post_custom = get_post_custom($post->ID);
$meta_value = $post_custom["$customkey"][0];
if( $meta_value ) {
$img_url = $meta_value;
$img_title = apply_filters('the_title', $post->post_title);
} else {
if( empty($post_image_attachments) ) {
$record = ( $wp_version < 2.1 ) ? 'post_status' : 'post_type';
$post_image_attachments = @$wpdb->get_results("SELECT ID, post_parent, post_title, post_content, guid FROM $wpdb->posts WHERE post_parent IN($IN_ids) AND $record = 'attachment' AND post_mime_type LIKE '%image%' ORDER BY post_date ASC");
}

#echo sizeof($post_image_attachments);
foreach( $post_image_attachments as $attachment ) {

#echo "in foreach";
$img_url = $attachment->guid;
$img_title = apply_filters('the_title', $attachment->post_title);
$postmarked = strpos(strtolower($attachment->post_title), strtolower($customkey));
$fileimage = explode('.', basename($attachment->guid));
if( $postmarked == true || $post->ID == $fileimage[0] || $post->post_name == $fileimage[0] ) {
$img_url = $attachment->guid;
$img_title = apply_filters('the_title', $attachment->post_title);
if($postmarked == true) {
$img_title = trim(str_replace($customkey, '', $img_title));
break;
}
}

if( $use_thumb && ($img_url != $default_image) )
$img_url = preg_replace('!(\.[^.]+)?$!', __('.thumbnail') . '$1', $img_url, 1);
$img_path = ABSPATH . str_replace(get_settings('siteurl'), '', $img_url);
if( !file_exists($img_path) ) {
return;
} else {
if( $img_tag ) {
$imagesize = @getimagesize($img_url);
$image_link_url_array = explode('/', $img_url);
$image_link_filename = $image_link_url_array[sizeof($image_link_url_array) - 1];
$length_thumb_name = strlen($image_link_filename);
$image_link_filename_array = explode('.', $image_link_filename);
$image_link_filename = $image_link_filename_array[0] . '.' . $image_link_filename_array[sizeof($image_link_filename_array) - 1];

#echo $image_link_filename;
unset($image_link_url_array[sizeof($image_link_url_array) - 1]);
$image_link_url = substr($img_url, 0, strlen($img_url) - $length_thumb_name) . $image_link_filename;
$image = '<a href="' . $image_link_url . '" title="' . $img_title . '" rel="lightbox[slideshow]"><img class="' . $css_class . '" src="' . $img_url . '" ' . $imagesize[3] . ' title="' . $img_title . '" alt="' . $img_title . '" /></a>';
} else {
$image = $img_url;
}
}

if( $display )
echo $image;

# return $image;
}
if( !empty($default_image) && sizeof($post_image_attachments) == 0 ) {
$img_url = $default_image;
$img_title = apply_filters('the_title', $post->post_title);
if( $img_tag ) {
$imagesize = @getimagesize($img_url);
$image = '<img class="' . $css_class . '" src="' . $img_url . '" ' . $imagesize[3] . ' title="' . $img_title . '" alt="' . $img_title . '" />';
}

if( $display )
echo $image;
}
}
}

Теперь выводятся все привязанные картинки, а мне нужно первую отделить. Первая будет выводится функцией post_image(), скажем, слева, а остальные (начиная со второй) функцией post_image_multiple() справа.

Anonymous
Отправить
Ответ на: