海豚的WordPress Theme教程 part4

這回講index.php,從這篇開始我不帖相關的css內容了,因為詳細解釋css內容就變成css教程了,而事實上我自己都沒怎么搞清楚css,一般都是邊改邊學。需要相關css的可以直接去下載KD02模版,自己慢慢研究。

index.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php get_header(); ?>
<div id="content">
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div class="post">
<h1 id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h1>
<p class="date"><?php the_author() ?> @ <?php the_time() ?> <?php the_time('F jS, Y') ?></p>
<div class="entry">
<?php the_content('[more...]'); ?>
</div>
</div>
<div class="meta">
<?php the_category(', ') ?> <strong>|</strong> <?php edit_post_link('Edit','','<strong>|</strong>'); ?>? <?php comments_popup_link('Comments (0)', 'Comments (1)', 'Comments (%)'); ?>
</div>
<!--<?php trackback_rdf(); ?>-->
<?php endwhile; ?>
<div class="navigation">
<div class="alignleft"><?php posts_nav_link('','','? Previous Entries') ?></div>
<div class="alignright"><?php posts_nav_link('','Next Entries ?','') ?></div>
</div>
<?php else : ?>
<h2 class="center">Not found.</h2>
<p class="center"><?php _e("Sorry, but you are looking for something that isn't here."); ?></p>
<?php include (TEMPLATEPATH . "/searchform.php"); ?>
<?php endif; ?>
</div>
<!-- content -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>

line1, line43, line45: 負責把header.php, sidebar.php, footer.php的內容引入,這樣這幾部分就作為一個整體展現在訪問者面前了。
line5-line26: 其中內容就是每篇post在首頁的顯示內容。一般來說分成三個部分:標題,包括文章題目,作者名字,寫作時間;正文內容;留言提示,比如有多少留言,文章所屬分類。至于具體位置隨個人愛好,如果你不懂php也沒什么關系,隨便找一個模版然后依樣畫葫蘆copy & paste就可以了。
line28-line31: 導航欄。就是下一頁/上一頁這個東西。
line35-line37: 這個是當一篇文章都沒有的時候顯示的報措信息。
基本上index.php主要內容就是一個循環語句,不斷顯示每篇文章直到你后臺設定的那個顯示文章數為止。
這篇內容比較少,明天會把有關sidebar.php和footer.php的part5跟上。到part5其實整個模版就接近完成了,其他的幾個文件基本上都是從這幾個文件中演變出去,不會太費事。
海豚的這個簡單教程很快會結束,然后把Kamus要求修改的Blix模版完成,四月底想做一個新的模版。新模版可能會比較中規中矩,不過將會融入Widgets和WordPress Theme Toolkit或許還有AJAX效果的留言以方便后期修改。