WordPress: Extrakt ein Bild aus einer post mit catch_that_image
15 Oktober 2009 Geschrieben von: Sandro Modarelli
1 Kommentar
Veröffentlicht in Internet-Sites Design Blog
Ecco una semplice funzione per estrarre la prima immagine dal contenuto del vostro post.
function catch_that_image() { global $post, $posts; $first_img = ''; ob_start(); ob_end_clean(); $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $text, $matches); $first_img = $matches [1] [0]; // se non ci sono immagini nel post, restituisce un'immagine di default if(empty($first_img)){ $first_img = "/image/omg.png"; } return $first_img; }
Basterà inserirla nel file function.php del vostro theme per poi usarla dove più vi piace. Ich, oft, la uso con TimThumb su Wordpress per l’impaginazione della home page, für jeden Post auf das Bild schmücken.
Über den Autor
Sandro Modarelli
Sviluppatore PHP Symfony, SEO Spezialist, HTML & CSS-Code. Tech-Enthusiasten, war der schlimmste Mangel vorliegt: Neugier. Er liebt Herausforderungen und das Ziel ist sein Lieblingsessen












18:25 von 7 Januar 2010
Hallo, ho fatto tutto alla perfezione includendo anche lo script e timthumb segnalato qui: http://www.ideama.it/blog/aggiungere-timthumb-ad-un-template-wordpress/
Non riesco a capire, nonostante avendo inserito un’immagine in sito.ext/image/omg.png, Warum’ l’immagine di default non compare in assenza di immagini nel post e viene visualizzato un errore di visualizzazione immagine.