PERUSAHAAN WEB HOSTING MURAH, DOMAIN NAME DAN WEB DEVELOPMENT INDONESIA

Menampilkan image dengan custom field di WordPress 2.7.1

Posted on Wednesday, March 25th, 2009

Menampilkan image thumbnail dari setiap post di halaman depan blog. Untuk WordPress 2.7.1

Contoh:

1a

screenshot from x-phoneshop.com

Pada WP Admin, pilihlah salah satu post yang akan dibuatkan image thumbnail-nya untuk dimunculkan di halaman depan.

  1. 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.
  2. 2
  3. 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.
  4. Copy URL image location dari hasil upload tersebut. Contoh url location: http://localhost/wordpress27/wp-content/uploads/2009/01/sony_ericsson_w902_thumb.jpg
  5. 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=""/>
  6. 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"/>
  7. Klik tombol Update post untuk menyimpan hasil editing barusan.
  8. Pada menu admin, bukalah Editor yang ada di dalam menu Appereance untuk mengedit file themes.
  9. Pilih file index.php (Main index template). Kita akan menambahkan sebaris code php untuk menampilkan image di dalam custom field tadi.
  10. 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.

This entry was posted on Wednesday, March 25th, 2009 at 12:52 am and is filed under Tutorial. You can follow any responses to this entry through the RSS 2.0 feed.
  • http://republikblogger.com republik

    Manstabs

  • http://bemfema.ipb.ac.id/?p=18 Test : Bemfema IPB

    [...] ini lo link nya Berita [...]

  • http://homedesignart.com solichin

    Cara agar images saat di klik ada di template wordpress kita, itu gmn?

Diskon Hosting Indonesia
BOC support
BOC on Twitter

www.flickr.com
bali-orange's items Go to bali-orange's photostream
BaliBlogger
World Silent Day



eXTReMe Tracker