Скрипт работает следующим образом: допустим у вас есть много постов, в каком то из них есть миниатюра, в каком то нет. В тех где есть миниатюра – скрипт будет использовать её, в тех где нет, будет использоваться первая картинка с поста.
1. Добавляем код в то место где должна выводиться картинка
[php]<?php
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
the_post_thumbnail(‘article-thumb’);
} else {
echo main_image(); } ?>
[/php]
2. Добавляем в файл functions.php
[php]
// display the first image attachment
function main_image() {
$files = get_children(‘post_parent=’.get_the_ID().’&post_type=attachment
&post_mime_type=image&order=desc’);
if($files) :
$keys = array_reverse(array_keys($files));
$j=0;
$num = $keys[$j];
$image=wp_get_attachment_image($num, ‘large’, true);
$imagepieces = explode(‘"’, $image);
$imagepath = $imagepieces[1];
$main=wp_get_attachment_url($num);
$template=get_template_directory();
$the_title=get_the_title();
print "<img src=’$main’ alt=’$the_title’ class=’frame’ />";
endif;
}
[/php]





