Skip to content

Instantly share code, notes, and snippets.

@akinayturan
Last active August 29, 2015 14:15
Show Gist options
  • Save akinayturan/68c874069f72724f0293 to your computer and use it in GitHub Desktop.
Save akinayturan/68c874069f72724f0293 to your computer and use it in GitHub Desktop.
WP ~ Eklentisiz Yazıdaki İlk Resmi Alma & Gösterme
<?php
// Yazıdaki ilk resmi alma ve gösterme //datarar.com
function resimgoster() {
error_reporting(0);
global $post, $posts;
$resimbir = '';
ob_start();
ob_end_clean();
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
$resimbir = $matches [1] [0];
if(empty($resimbir)){ //Eğer resim eklememişseniz
$resimbir = '//datarar.com/dr/tanitim/datarar-com-banner-149-149.jpg';
}
return $resimbir;
}
function resimgoster_by_post($post) {
error_reporting(0);
$resimbir = '';
ob_start();
ob_end_clean();
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
$resimbir = $matches [1] [0];
if(empty($resimbir)){ //Eğer resim eklememişseniz
$resimbir = '//datarar.com/dr/tanitim/datarar-com-banner-149-149.jpg';
}
return $resimbir;
}
?>
<img src="<?php echo resimgoster(); ?>" alt="resim" width="200px" height="200px" />
<?php echo resimgoster(); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment