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