Memunculkan Sekian Postingan untuk Kategori Tertentu

Untuk memunculkan sekian postingan untuk kategori tertentu bisa diselesaikan dengan script berikut ini.
<?php
//memunculkan 5 posts untuk kategori dengan nomer id 18
$args=array(
'cat' => 18,
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => 5,
'caller_get_posts'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
echo '';
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<p><li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a> - <class id="waktu"> <?php the_time('d/m') ?></p>
<?php
endwhile;
}
wp_reset_query(); // Restore global post data stomped by the_post().
?>

keterangan:

  1. cat=> artinya kode id untuk kategori. kawan bisa lihat dengan mengarahkan ke link dategori pada dashboard. di taskar akan muncul category idnya.

  2. post_per_page=>berapa jumlah postingan yang akan dimunculkan.

  3. sedangkan the_time akan menampilkan waktu/tanggal terbit.


settingan the_time

F j, Y g:i a bearti November 6, 2010 12:50 am
F j, Y bearti November 6, 2010
F, Y bearti November, 2010
g:i a bearti 12:50 am
g:i:s a bearti 12:50:48 am
l, F jS, Y bearti Saturday, November 6th, 2010
M j, Y @ G:i bearti Nov 6, 2010 @ 0:50
Y/m/d \a\t g:i A bearti 2010/11/06 at 12:50 AM
Y/m/d \a\t g:ia bearti 2010/11/06 at 12:50am
Y/m/d g:i:s A bearti 2010/11/06 12:50:48 AM
Y/m/d bearti 2010/11/06
Share on Google Plus

About JackSparrow

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment

0 komentar:

Post a Comment