Membuat File index.php


Setelah kita membuat file header.php, sidebar.php dan footer.php, maka langkah selanjutnya adalah membuat file index.php. File index.php berguna untuk menampilkan halaman utama sebuah blog. Ketika alamat blog diketik pada browser maka halaman index.php lah yang pertama kali dicari kemudian dibuka.
Halaman yang dibuka oleh file index.php memenuhi struktur theme wordpress. Struktur theme wordpress tersebut terdiri dari header, konten, sidebar, dan footer. Jadi kode-kode pada file index.php berguna untu memanggil file header.php, sidebar.php dan footer.php yang sebelumnya telah kita buat.
Simpan file dengan nama 'index-php' berikut kode-kode dasarnya:

<?php get_header(); ?>
<div id="content">
<?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() ?>"><?php the_title(); ?></a></h2>
<small><?php the_time(__('F jS, Y')) ?> <!-- by <?php the_author() ?> --></small>
<?php the_content(__('Read more...')); ?>
<p><small><?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') ); ?></small></p>
</div>
<?php endwhile; ?>
<p class="navigation">
<div class="alignleft"><?php next_posts_link(__('&laquo; Older Entries')) ?></div>
<div class="alignright"><?php previous_posts_link(__('Newer Entries &raquo;')) ?></div>
</p>
<?php else : ?>
<h2 class="center"><?php _e('Not Found'); ?></h2>
<p class="center"><?php _e('Sorry, but you are looking for something that isn&#8217;t here.'); ?></p>
<?php get_search_form(); ?>
<?php 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(); ?> adalah konten blog. Isi utama sebuah halaman blog dan merupakan bagian yang paling penting terdapat pada konten ini.
  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