Menampilkan image thumbnail dari setiap post di halaman depan blog. Untuk WordPress 2.7.1
Contoh:
screenshot from
Pada WP Admin, pilihlah salah satu post yang akan dibuatkan image thumbnail-nya untuk dimunculkan di halaman depan.
- Dalam menu edit sebuah post, buatkan custom field pada sebuah post dengan key “the_excerpt_image ” pada menu custom field di bagian bawah halaman edit post.
-

- Upload image dengan ukuran thumbnail (besar pixel width dan height bebas sesuai theme), lalu gunakan fungsi upload pada wp-admin untuk meletakkan image tersebut di wp-content/uploads.
- Copy URL image location dari hasil upload tersebut. Contoh url location:
http://localhost/wordpress27/wp-content/uploads/2009/01/sony_ericsson_w902_thumb.jpg - Pada custom field dengan key “the_excerpt_image” yang tadi dibuat, buatkan code html untuk menampilkan image pada kolom value di sebelahnya. Contoh:
<img src="" alt=""/> - Paste url location image-nya di tag src=”". Contoh:
<img src="http://localhost/wordpress27/wp-content/uploads/2009/01/sony_ericsson_w902_thumb.jpg" alt="image"/> - Klik tombol Update post untuk menyimpan hasil editing barusan.
- Pada menu admin, bukalah Editor yang ada di dalam menu Appereance untuk mengedit file themes.
- Pilih file index.php (Main index template). Kita akan menambahkan sebaris code php untuk menampilkan image di dalam custom field tadi.
- Di dalam file index.php, temukan baris code
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>. Baris ini adalah baris awal fungsi loop wordpress yang menampilkan semua post di halaman depan. Sebelumnya, pastikan CHMOD file index.php ke 777 untuk membuat file ini editable. Lalu copy code ini:
//show small image from custom field
$key="the_excerpt_pict";
echo get_post_meta($post->ID, $key, true);
?>
dan kemudian paste di dalam loop dimana thumbnail image tadi akan dimunculkan. Contoh:
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
<small><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></small>
<div class="entry">
<?php
//show small image from custom field the_excerpt_pict
$key="the_excerpt_pict";
echo get_post_meta($post->ID, $key, true);
?>
<?php the_content('Read the rest of this entry »'); ?>
</div>
<p class="postmetadata"><?php the_tags('Tags: ', ', ', '<br />'); ?> Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?> <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></p>
</div>
<?php endwhile; ?>
<?php else : ?>
notes: loop di atas diambil dari index.php dari themes default wordpress
10. Klik tombol Update file untuk menyimpan hasil editing pada file index.php barusan.
11. Refresh halaman depan blog Anda untuk melihat hasilnya.
