海豚的WordPress Theme教程 part4

這回講index.php,從這篇開(kāi)始我不帖相關(guān)的css內(nèi)容了,因?yàn)樵敿?xì)解釋css內(nèi)容就變成css教程了,而事實(shí)上我自己都沒(méi)怎么搞清楚css,一般都是邊改邊學(xué)。需要相關(guān)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: 負(fù)責(zé)把header.php, sidebar.php, footer.php的內(nèi)容引入,這樣這幾部分就作為一個(gè)整體展現(xiàn)在訪問(wèn)者面前了。
line5-line26: 其中內(nèi)容就是每篇post在首頁(yè)的顯示內(nèi)容。一般來(lái)說(shuō)分成三個(gè)部分:標(biāo)題,包括文章題目,作者名字,寫(xiě)作時(shí)間;正文內(nèi)容;留言提示,比如有多少留言,文章所屬分類(lèi)。至于具體位置隨個(gè)人愛(ài)好,如果你不懂php也沒(méi)什么關(guān)系,隨便找一個(gè)模版然后依樣畫(huà)葫蘆copy & paste就可以了。
line28-line31: 導(dǎo)航欄。就是下一頁(yè)/上一頁(yè)這個(gè)東西。
line35-line37: 這個(gè)是當(dāng)一篇文章都沒(méi)有的時(shí)候顯示的報(bào)措信息。
基本上index.php主要內(nèi)容就是一個(gè)循環(huán)語(yǔ)句,不斷顯示每篇文章直到你后臺(tái)設(shè)定的那個(gè)顯示文章數(shù)為止。
這篇內(nèi)容比較少,明天會(huì)把有關(guān)sidebar.php和footer.php的part5跟上。到part5其實(shí)整個(gè)模版就接近完成了,其他的幾個(gè)文件基本上都是從這幾個(gè)文件中演變出去,不會(huì)太費(fèi)事。
海豚的這個(gè)簡(jiǎn)單教程很快會(huì)結(jié)束,然后把Kamus要求修改的Blix模版完成,四月底想做一個(gè)新的模版。新模版可能會(huì)比較中規(guī)中矩,不過(guò)將會(huì)融入Widgets和WordPress Theme Toolkit或許還有AJAX效果的留言以方便后期修改。