[help] modifikasi script get_first_image() di WordPress


Status
Not open for further replies.

Fadli

Poster 2.0
ehm...malu juga sih sebenernya buka thread lagi yang isinya cuma bisa minta tolong... :D
tapi kalo ga nanya, nanti masalah saya ga selese2 :(

begini...saya dapet script ini dari blog orang luar untuk misahin & nempatin ulang posisi image pertama yang ada di sebuah postingan. trus saya bikin modifikasinya kayak gini dg tambahan script thimthumb:

file functions.php:
PHP:
function get_first_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 = get_bloginfo('template_url').'/images/nopic.gif';

  }
  return $first_img;
}

file index.php:
PHP:
<!-- slider -->
<div class="slider">
	<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><img src="<?php echo get_first_image() ?>" alt="<?php the_title(); ?>" height="300" width="600" /></a>
</div>

<!-- content -->
<div class="content">
	<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><img src="<?php bloginfo('template_url'); ?>/scripts/timthumb.php?src=<?php echo get_first_image() ?>&h=80&w=150" alt="<?php the_title(); ?>" /></a>
	<?php content(); ?>
</div>
yang jadi masalah saya, kalau untuk gambar di bagian slider, saya sudah pas dengan settingan seperti itu. tapi untuk gambar yang di bagian content, saya masih kurang pas ketika ada suatu postingan yang ga punya gambar, karena ngikut settingan get_first_image() maka dia akan tetap menampilkan gambar nopic.gif. sedangkan saya maunya untuk bagian content dia ga usah nampilin gambar nopic seperti di bagian slider.

kira-kira coding seperti apa yang perlu saya tambahkan di bagian contentnya ya? Soalnya kalau misalkan saya bikin 2 coding seperti get_first_image1() dan get_first_image2() rasanya kok lucu gitu ya... ehehehe :D


mohon bantuannya sekali lagi ya ... makasih banyak!!
 
Status
Not open for further replies.

Top