wordpress 修改首頁的文章顯示方式
參考資料 http://pangbu.com/get_template_part/
最近因為一些緣故,又要做wordrpess 網站
首先最大的麻煩是首頁的文章排列方式
修改的方法
外觀->主題編輯器
選擇你現在使用的主題,如果不能存檔,請先進到FTP裡修改檔案存取權限
首頁 修改是在 index.php,請仔細看內容
會找到
<?php while ( have_posts() ) : the_post(); ?> <?php get_template_part( 'content', get_post_format() ); ?> <?php endwhile; ?>
這種東西
裡面總共出現了四個function
have_posts() 這個很好懂吧,有沒有文章
the_post () 這個應該是把文章取出一篇
get_template_part() 這個就是我們今天的重點了,這個變數目的是在 讓接下來的文章顯示可以有多種不同選擇
get_template_part($a,$b) 有兩個變數,簡單來說就是,執行後 系統會去選擇$a-$b.php 這個檔案去執行接下來的內容
而get_post_format()就是 依照文章格式,這是在你PO文的時候選擇的,如果你選標準就是啥都沒有
接下來 就是去找其他檔案的內容了
接下來我已我用 artisteer 產生的佈景主題為例
首頁的內容 會使用到content.php 這個檔案
global $post;
theme_post_wrapper(
array(
'id' => theme_get_post_id(),
'class' => theme_get_post_class(),
'thumbnail' => theme_get_post_thumbnail(),
'title' => '<a href="' . get_permalink( $post->ID ) . '" rel="bookmark" title="' . strip_tags(get_the_title()) . '">' . get_the_title() . '</a>',
'heading' => theme_get_option('theme_'.(is_single()?'single':'posts').'_article_title_tag'),
'before' => theme_get_metadata_icons( 'date,author,edit', 'header' ),
'content' => theme_get_excerpt(),
'after' => theme_get_metadata_icons( 'category,tag,comments', 'footer' )
)
);
而這裡就是把資料放進array中到接下來的wrapper.php檔案中使用
依照之前的code 我們知道會執行theme_post_wrapper()
而這支佈景主題的作法是,一個公版,但是在前一個步驟你沒放資料進來就不會顯示內容
好 理解了應該就很好修改
要修改有兩種方法
比較簡單的
修改content.php 把不要的註解掉,這個最簡單,但是有可能影響到其他地方
比較複雜的,仿造從寫一個,從index.php開始修改,這樣改比較刺激XD
theme_post_wrapper这种主题写法挺新颖,受益。