Posted by: murdanieko on: August 4, 2010
Serupa dengan postingan tentang gambar attachment otomatis, untuk kali ini saya menggunakan function satu lagi untuk menampilkan hanya satu buah gambar terakhir dari semua attachment posting tertentu.
<?php
//start thumbimage code
function thumbimage($size=large) {
if ( $images = get_children(array(
'post_parent' => get_the_ID(),
'post_type' => 'attachment',
'numberposts' => 1,
'post_mime_type' => 'image',)))
{
foreach( $images as $image ) {
$attachmenturl=wp_get_attachment_url($image->ID);
$attachmentimage=wp_get_attachment_image( $image->ID, $size );
echo $attachmentimage;
}
} else {
echo "No Image";
}
}
//end thumbimage code
?>
Untuk menarik gambar attachment ke halaman index atau categories, pakai kode ini
<?php thumbimage('large'); ?>
Sesuaikan nilai large dengan ukuran yang dikehendaki (thumbnail, medium, atau large)
August 30, 2010 at 9:23 am
bro… diletakin dmn ne code?
January 20, 2011 at 10:30 am
untuk kode yang panjang, taruh di function.php. Itu ada di direktori theme yang sedang digunakan. Klo yang pendek diletakkan di halaman index.php atau archives.php atau single.php. Terserah keperluan