Sådan får man WP til automatisk at generer thunbnails:)
Dette skal i din .php:
function catch_that_image() {
global $post, $posts;
$first_img = '';
ob_start();
ob_end_clean();
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
$first_img = $matches [1] [0];
if(empty($first_img)){ //Defines a default image
$first_img = "/images/default.jpg";
}
return $first_img;
}
Også kan du kalde billederne med denne kommando:
<?php echo catch_that_image() ?>
Du kan finde det hele her
Hvis du gerne vil have linket, uden dit Side-url foran, kan du tilføje denne kode:
$first_img = str_replace(‘http://yourwebsite.com’, ”, $first_img);
Så det hele bliver:
function catch_that_image() {
global $post, $posts;
$first_img = '';
ob_start();
ob_end_clean();
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
$first_img = $matches [1] [0];
// no image found display default image instead
if(empty($first_img)){
$first_img = "/images/default.jpg";
}
$first_img = str_replace('http://yourwebsite.com', '', $first_img);
return $first_img;
}
Related posts:
