Я столкнулся с тем же самым, когда разрабатывал свою собственную тему.Вот как я это решил.
Начните с добавления возможности избранных изображений в ваши functions.php.
if (function_exists('add_theme_support')) {
add_theme_support('post-thumbnails');
}
Это позволяет вам выбирать избранные изображения для каждого сообщения.
С помощью показанного изображенияДоступная функция: вы можете использовать следующую функцию, чтобы определить, есть ли у сообщения избранное изображение ... в форме цикла:
$args = array(
'post_type' => 'ad_listing'
);
query_posts($args);
if ( have_posts() ) :
while ( have_posts() ) : the_post();
if ( has_post_thumbnail() ) { //For featured images
//For post images/attachments
ob_start();
the_id();
$postID = ob_get_clean();
$args = array(
'numberposts' => 1,
'order'=> 'ASC',
'post_mime_type' => 'image',
'post_parent' => $postID,
'post_status' => null,
'post_type' => 'attachment'
);
$images =& get_children($args);
if ( empty($images) ) {
//What to do without images
}
else {
//What to do with images
}
}
endwhile;
else :
//What happens when no posts are found
endif;
Надеюсь, это поможет.