- JEVUSKA - http://www.jevuska.com -
Thumbnail di Random Posts dan Recent Posts
Posted By Jevuska On April 23, 2010 @ 9:20 am In Tutorial | 8 Comments
Sudah bisa menampilkan random posts atau recent posts di blog WordPress kamu? Hasil yang ditampilkan dari kedua skrip random posts dan recent posts pada postingan saya sebelumnya memang tidak memunculkan gambar jika post kamu ada gambarnya. Artikel postingan yang muncul juga hanya excerpt (summary) nya saja. Sekarang kita coba menampilkan thumbnail dari kedua skrip tersebut.
1. Buka function.php theme blog kamu dan kopas kode berikut. (simpan aja di bagian paling bawah kode-kode dalam function.php)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | < ?php function the_image($size = 'medium' , $class = ”){ global $post; //setup the attachment array $att_array = array( 'post_parent' => $post->ID, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order_by' => 'menu_order' ); //get the post attachments $attachments = get_children($att_array); //make sure there are attachments if (is_array($attachments)){ //loop through them foreach($attachments as $att){ //find the one we want based on its characteristics if ( $att->menu_order == 0){ $image_src_array = wp_get_attachment_image_src($att->ID, $size); //get url – 1 and 2 are the x and y dimensions $url = $image_src_array[0]; $caption = $att->post_excerpt; $image_html = '<img align="left" style="padding:0 4px 4px 0" width="50px" src="%s" alt="%s" class="thumb-home"/>'; //combine the data $html = sprintf($image_html,$url,$caption,$class); //echo the result echo $html; } } } } ?> |
Kode < ?php pada line 1 agak terpisah, dirapatkan aja kek gini <?php
Kode line 27 berisi ukuran thumbnail (width=”50px” dan penempatan gambar (align=”left”). Kamu modifikasi sendiri jika diperlukan.
2. Kemudian tambahkan kode berikut pada line 9 kode -> Random Posts atau Recent Posts:
< ?php the_image('thumbnail','post-thumb');?> |
Jadinya seperti ini:
8 9 10 | ...... <div class="entry">< ?php the_image('thumbnail','post-thumb');?>< ?php the_excerpt(); ?> </div> ...... |
Pastikan dulu semua kode < ?php dirapatkan kayak gini <?php
Thumbnail akan muncul, apabila postingan kamu berisi gambar. Jika mau menggunakan skrip ini, pastikan dulu semua postingan berisi gambar supaya tampilannya lebih baik. Selamat mencoba Sob!
Baca juga bagaimana pasang thumbnail di Auto-Generated Content.
Article printed from JEVUSKA: http://www.jevuska.com
URL to article: http://www.jevuska.com/2010/04/23/thumbnail-di-random-posts-dan-recent-posts
Click here to print. Click here for download (Internet Explorer only)
Copyright © 2009 JEVUSKA. All rights reserved.