функция для определения первой картинки в посте
function post_first_image() {
global $post;
$first_img = '';
if ($post == NULL)
return false;
else {
$output = preg_match_all('/<img[^>]+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
if(isset($matches[1][0]) ){
$first_img = $matches[1][0];
} else {
return false;
}
return $first_img;
}
}
вывожу похожие посты на single.php
<div class="related">
<h3>Дополнительные записи</h3>
<ul>
<?php
$categories = get_the_category($post->ID);
if ($categories) {
$category_ids = array();
foreach($categories as $individual_category) $category_ids[] = $individual_category->term_id;
$args=array(
'category__in' => $category_ids,
'post__not_in' => array($post->ID),
'showposts'=>3, // Количество выводимых записей
'caller_get_posts'=>1
);
$my_query = new wp_query($args);
if( $my_query->have_posts() ) {
echo '';
while ($my_query->have_posts()) {
$my_query->the_post();
?>
<li class="post_mini">
<h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
<a class="post_thumbnail" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" alt=""><img src+"<?php post_first_image(array( 234,124)); ?>" /></a>
</li>
<?php
}
echo '';
}
wp_reset_query();
}
?>
</ul>
</div>
но не могу понять, почему не выводятся картинки