DimWM

Вывод тумб со ссылкой на пост

добрый день 🙂

хочу вывести на главной странице тумбы со ссылкой на пост откуда это изображение было взято. я сделал следующие:
1. вставил следующий код в function.php

<?php
function full_to_thmb($content) {

 if (!is_single() && !is_page() ) {
    $content = preg_replace_callback("/<img.*?>/mi", 'full_to_thmb_cb', $content);
    $link = get_permalink();
    $full = array ("'<a href.*>(<img .*?>)</a>'mi","'(<img .*?>)'i");
    $thmb = array ("<a href=\"$link\">$1</a>","<a href=\"$link\">$1</a>");
    $content = preg_replace($full,$thmb,$content);

 }
    return $content;

}

function full_to_thmb_cb($m) {
    $sq = 1000000;
    if (stristr($m[0],get_bloginfo('url')) == false) return $m[0];
    preg_match('%src="'.get_bloginfo('url').'(/.*)/(.*?)(?:-\d+x\d+)?\.(.*?)"%',$m[0],$mmm);
    if ($dir = @opendir(ABSPATH.$mmm[1])) {
        while($file = readdir($dir)) {
            if (strstr($file,$mmm[2]) === false) continue;
            if (strstr($file,'.thumbnail.')) { $thmb = $file; $sq = 0; break; }
            if (preg_match('"-(\d+)x(\d+)\.(jpg|jpeg|gif|png)$"i',$file,$ff)) {
                if ($ff[1]*$ff[2] < $sq) {$thmb = $file; $sq = $ff[1]*$ff[2];}
            }
        }
    }    
    if ($sq<1000000) return '<img src="'.get_bloginfo('url').$mmm[1].'/'.$thmb.'" width="100" height="100" class="size-thumbnail">';
    else return $m[0];
}

add_filter('the_content','full_to_thmb',100000);
?>

2. вставил код в файл home.php

<?php query_posts('showposts=1000'); ?>
<?php while (have_posts()) : the_post(); ?>
<?php echo full_to_thmb($post->post_content) ?>
<?php endwhile; ?>

в результате получил:

<a href="post_url"><img src="img_urlg" width="100" height="100" class="size-thumbnail"></a><!--more-->текст статьи...

<a href="post_url"><img src="img_url" width="100" height="100" class="size-thumbnail"></a><!--more-->текст статьи...

<a href="post_url"><img src="img_url" width="100" height="100" class="size-thumbnail"></a><!--more-->текст статьи...

<a href="post_url"><img src="img_url" width="100" height="100" class="size-thumbnail"></a><!--more-->текст статьи...

...

всё вроде бы хорошо. НО!
как сделать что бы выводились только картинки? то есть без текста из записи и прочей ерунды… вобщем только одни картинки со ссылками на записи!

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