Membuat File archive.php


File archive.php berfungsi menampilkan halaman arsip blog. Kegunaan arsip adalah menempatkan posting ke dalam kelompok-kelompoknya. Arsip blog bisa berupa arsip posting per bulan, arsip posting per category atau arsip tag.
Prinsip pembuatan file archive.php sama dengan file index.php, yaitu memanggil file header.php, sidebar.php dan footer.php. Perbedaannya terdapat pada isi konten yang disajikan.

Berikut kode-kode yang digunakan untuk membuat file archive.php. Kode di bawah disalin ke dalam sebuah teks editor kemudian disimpan dengan nama archive.php.

<?php get_header(); ?>
<div id="content">
<?php if (have_posts()) : ?>
<?php $post = $posts[0];?>
<?php if (is_category()) { ?>
<h2><?php printf(__('Archive for the ‘%s’ Category'), single_cat_title('', false)); ?></h2>
<?php } elseif( is_tag() ) { ?>
<h2><?php printf(__('Posts Tagged ‘%s’'), single_tag_title('', false) ); ?></h2>
<?php } elseif (is_day()) { ?>
<h2><?php printf(_c('Archive for %s|Daily archive page'), get_the_time(__('F jS, Y'))); ?></h2>
<?php } elseif (is_month()) { ?>
<h2><?php printf(_c('Archive for %s|Monthly archive page'), get_the_time(__('F, Y'))); ?></h2>
<?php } elseif (is_year()) { ?>
<h2><?php printf(_c('Archive for %s|Yearly archive page'), get_the_time(__('Y'))); ?></h2>
<?php } elseif (is_author()) { ?>
<h2><?php _e('Author Archive'); ?></h2>
<?php } elseif (isset($_GET['paged']) && !empty($_GET['paged'])) { ?>
<h2><?php _e('Blog Archives'); ?></h2>
<?php } ?>
<div class="navigation">
<div class="alignleft"><?php next_posts_link(__('« Older Entries')); ?></div>
<div class="alignright"><?php previous_posts_link(__('Newer Entries &raquo;')); ?></div>
</div>
<?php while (have_posts()) : the_post(); ?>
<div <?php post_class(); ?>>
<h2><a href="">></a></h2>
<small><?php the_time(__('l, F jS, Y')) ?></small>
<div class="entry">
<?php the_excerpt() ?>
</div>
<p><?php the_tags(__('Tags:'), ', ', '
'); ?
> <?php printf(__('Posted in %s'), get_the_category_list(', ')); ?> | <?php edit_post_link(__('Edit'), '', ' | '); ?> <?php comments_popup_link(__('No Comments &#187;'), __('1 Comment &#187;'), __('% Comments &#187;'), '', __('Comments Closed') ); ?></p>
</div>
<?php endwhile; ?>
<div class="navigation">
<div class="alignleft"><?php next_posts_link(__('&laquo; Older Entries')); ?></div>
<div class="alignright"><?php previous_posts_link(__('Newer Entries &raquo;')); ?></div>
</div>
<?php else :
if ( is_category() ) {
printf("
<h2 class='center'>".__("Sorry, but there aren't any posts in the %s category yet.").'</h2>', single_cat_title('',false));
} else if ( is_date() ) {
echo('
<h2>'.__("Sorry, but there aren't any posts with this date.").'</h2>');
} else if ( is_author() ) {
$userdata = get_userdatabylogin(get_query_var('author_name'));
printf("
<h2 class='center'>".__("Sorry, but there aren't any posts by %s yet.")."</h2>", $userdata->display_name);
} else {
echo("
<h2 class='center'>".__('No posts found.').</h2>');
}
get_search_form();
endif;
?
>
</div>

<?php get_sidebar(); ?>
<?php get_footer(); ?>

Keterangan:
  1. Kode <?php get_header(); ?> berguna untuk memanggil file header.php.
  2. Kode <div id="content"> sampai kode </div> sebelum kode <?php get_sidebar(); ?> merupakan konten blog. Isi dari konten blog ini nantinya adalah arsip.
  3. Kode <?php get_sidebar(); ?> berguna untuk memanggil file sidebar.php.
  4. Kode <?php get_footer(); ?> berguna untuk memanggil file footer.php.

Posting Komentar

0 Komentar