學習typecho主題開發筆記01,typecho主題筆記01
部落格被加速樂坑掉,於是有了學習typecho主題開發的想法,感謝這個機會!
首先是去看主題檔案夾下面的'index.php',一個部落格的文章頁面一般包括下面幾個基本元素
- 作者
- 發表時間
- 文章分類 1 php 2 /** 3 * 這是 Typecho 0.9 系統的一套預設皮膚 4 * 5 * @package Typecho Replica Theme 6 * @author Typecho Team 7 * @version 1.2 8 * @link http://typecho.org 9 */10 11 if (!defined('__TYPECHO_ROOT_DIR__')) exit;12 $this->need('header.php');13 ?>14 15 class="col-mb-12 col-8" id="main" role="main">16 while($this->next()): ?>17 class="post" itemscope itemtype="http://schema.org/BlogPosting">18
class="post-title" itemprop="name headline">$this->permalink() ?>">$this->title() ?>
19
class="post-meta">20
- $this->author->permalink(); ?>" rel="author">$this->author(); ?>
21
- <time datetime="$this->date('c'); ?>" itemprop="datePublished">$this->date('F j, Y'); ?>time>
22
- $this->category(','); ?>
23
- $this->permalink() ?>#comments">$this->commentsNum('評論', '1 條評論', '%d 條評論'); ?>
24
25 class="post-content" itemprop="articleBody">26 $this->content('- 閱讀剩餘部分 -'); ?>27 28 29 endwhile; ?>30 31 $this->pageNav('« 前一頁', '後一頁 »'); ?>32 33 34 $this->need('sidebar.php'); ?>35 $this->need('footer.php'); ?
下面是這是index.php的原始碼:
1 php 2 /** 3 * 這是 Typecho 0.9 系統的一套預設皮膚 4 * 5 * @package Typecho Replica Theme 6 * @author Typecho Team 7 * @version 1.2 8 * @link http://typecho.org 9 */10 11 if (!defined('__TYPECHO_ROOT_DIR__')) exit;12 $this->need('header.php');13 ?>14 15 class="col-mb-12 col-8" id="main" role="main">16 while($this->next()): ?>17 class="post" itemscope itemtype="http://schema.org/BlogPosting">18 class="post-title" itemprop="name headline">$this->permalink() ?>">$this->title() ?>
19
class="post-meta">20
- $this->author->permalink(); ?>" rel="author">$this->author(); ?>
21
- <time datetime="$this->date('c'); ?>" itemprop="datePublished">$this->date('F j, Y'); ?>time>
22
- $this->category(','); ?>
23
- $this->permalink() ?>#comments">$this->commentsNum('評論', '1 條評論', '%d 條評論'); ?>
24
25 class="post-content" itemprop="articleBody">26 $this->content('- 閱讀剩餘部分 -'); ?>27 28 29 endwhile; ?>30 31 $this->pageNav('« 前一頁', '後一頁 »'); ?>32 33 34 $this->need('sidebar.php'); ?>35 $this->need('footer.php'); ?>
2-9行是注釋,裡麵包含了主題的各種資訊,每行以*開頭。
@package 表示主題的名稱
@author 表示作者資訊
@version 表示主題當前的版本
@link 表示作者的網站連結
include()方法用來包含要用到的php檔案,具體用法查閱PHP官方手冊include()方法
在12,34,35行都能看到$this->need(),它在typecho裡面就和include()的作用是一樣的
$this->need('header.php');$this->need('sidebar.php'); ?>$this->need('footer.php'); ?>
所以上面的代碼就是調用header.php,sidebar.php,footer.php。具體這三個php檔案是什麼作用的,很簡單,顧名思義哦!
然後就是文章頁面的主體了
class="col-mb-12 col-8" id="main" role="main"> while($this->next()): ?> class="post" itemscope itemtype="http://schema.org/BlogPosting"> class="post-title" itemprop="name headline">$this->permalink() ?>">$this->title() ?>
class="post-meta">
- $this->author->permalink(); ?>" rel="author">$this->author(); ?>
- <time datetime="$this->date('c'); ?>" itemprop="datePublished">$this->date('F j, Y'); ?>time>
- $this->category(','); ?>
- $this->permalink() ?>#comments">$this->commentsNum('評論', '1 條評論', '%d 條評論'); ?>
class="post-content" itemprop="articleBody"> $this->content('- 閱讀剩餘部分 -'); ?> endwhile; ?> $this->pageNav('« 前一頁', '後一頁 »'); ?>
endwhile是什麼鬼????為什麼我重來沒用過....查閱了下資料,原來是一種文法糖:)
文章主體就是從這裡開始到結束的
while($this->next()): ?>endwhile; ?>
:替代了{
;替代了}
詳細見文章:PHP中流程式控制制的替代文法
接著就是一些方法了
$this->permalink() ?> 文章所在的串連$this->title() ?> 文章標題$this->author(); ?> 文章作者$this->author->permalink(); ?> 文章作者地址$this->date('F j, Y'); ?> 文章的發布日期,格式可參考PHP日期格式$this->category(','); ?> 文章所在分類$this->commentsNum('%d Comments'); ?> 文章評論數及串連$this->content('Continue Reading...'); ?> 文章內容,其中的“Continue Reading…” 是顯示摘要時隱藏部分的文字
_e()這是什麼方法,專一而精十
看了下wordpress裡面的_e()方法,居然是用作翻譯的。。。難道typecho還有歪果仁使用(逃
直接列印輸出到 html 中的字串,就用 _e() 。具體看這裡
在代碼裡面還能看見itemprop屬性,這是html5新加的,暫時不用管他Q.Q
最後是一個分頁的方法
$this->pageNav(); ?>
至此,index.php檔案已經被分析一遍了,雖然我沒有php基礎,但是學習了之後發現不難,嘿嘿!繼續努力!
http://www.bkjia.com/PHPjc/1074252.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1074252.htmlTechArticle學習typecho主題開發筆記01,typecho主題筆記01 部落格被加速樂坑掉,於是有了學習typecho主題開發的想法,感謝這個機會! 首先是去看主題檔案夾下...