模板的製作並非難事,只要你寫好了HTML和CSS,嵌套模板就非常簡單了,你無需瞭解標籤的內部結構,你只要會使用,模板就能迅速完成。這篇文章只簡單的介紹了常用標籤的使用方法,希望能帶你進入模板的世界。
模板信息
我們先從主文件說起,打開這個文件,首先看到的是註釋:
/**
* 這是typecho系統的一套默認皮膚。你可以在<a href="http://typecho.org">typecho的官方網站</a>獲得更多關於此皮膚的信息
*
* @package Typecho Default Theme
* @author typecho
* @version 1.0.0
* @link http://typecho.org
*/這是模板信息存放的地方,它將在後臺都模板選擇頁顯示。
前兩行是簡短的介紹,每個“*”表示一個段落。
@package 表示模板名,
@author 表示作者名,
@version 是模板的版本號,
@link 是作者的網站連接。
緊挨着註釋下方的 include('header.php'),在結尾處也會看到 include('sidebar.php') 和 include('footer.php')。這些語句用來調用模板的其它模塊。header故名思議是頁首,sidebar是側欄,footer是頁腳。
顯示文章
<?php while($this->next()): ?>
<div class="post">
<h2 class="entry_title"><a href="<?php $this->permalink() ?>"><?php $this->title() ?></a></h2>
<div class="entry_data">
Published by <a href="<?php $this->author->permalink(); ?>"><?php $this->author(); ?></a> on <?php $this->date('F j, Y'); ?> in <?php $this->category(','); ?>.
<?php $this->commentsNum('%d Comments'); ?>.
</div>
<div class="entry_text">
<?php $this->content('Continue Reading...'); ?>
</div>
</div>
<?php endwhile; ?>進入文章循環,輸出文章,剝開html代碼,一句一句介紹
<?php $this->permalink() ?> 文章所在的連接
<?php $this->title() ?> 文章標題
<?php $this->author(); ?> 文章作者
<?php $this->author->permalink(); ?> 文章作者地址
<?php $this->date('F j, Y'); ?> 文章的發佈日期,格式可參考PHP日期格式
<?php $this->category(','); ?> 文章所在分類
<?php $this->commentsNum('%d Comments'); ?> 文章評論數及連接
<?php $this->content('Continue Reading...'); ?> 文章內容,其中的“Continue Reading…”是顯示摘要時隱藏部分的邀請連接好了,文章顯示結束,別忘了結束循環。
文章分頁
<?php $this->pageNav(); ?>文章輸出結束後別忘了增加分頁,至此,index.php的常見內容結束,應該不糊塗吧。