1、将首頁面index.php分成不同的模闆
- 建立header.php(頭部)、sidebar.php(工具欄)、footer.php等模闆
-
将對應的子產品代碼方法這些模闆裡面如header.php内容包括head聲明的屬性、頭部導航欄(封裝成頭部模闆,以供多個頁面複用)代碼:
-`
<title><?php bloginfo('name'); ?><?php wp_title(); ?></title>
<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />
<meta name="generator" content="WordPress <?php bloginfo('version'); ?>" /> <!-- leave this for stats please -->
<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" target="_blank" rel="external nofollow" type="text/css" media="screen" />
<link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="<?php bloginfo('rss2_url'); ?>" target="_blank" rel="external nofollow" />
<link rel="alternate" type="text/xml" title="RSS .92" href="<?php bloginfo('rss_url'); ?>" target="_blank" rel="external nofollow" />
<link rel="alternate" type="application/atom+xml" title="Atom 0.3" href="<?php bloginfo('atom_url'); ?>" target="_blank" rel="external nofollow" />
<link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" target="_blank" rel="external nofollow" />
<?php wp_get_archives('type=monthly&format=link'); ?>
<?php //comments_popup_script(); // off by default ?>
<?php wp_head(); ?>
<h1><a href="<?php bloginfo('url'); ?>" target="_blank" rel="external nofollow" ><?php bloginfo('name'); ?></a></h1>
<?php bloginfo('description'); ?>
</div>`
- 在index引用隻需使用WordPress的特用函數:get_header();(其他子產品的引用也是使用:get_sidebar();、get_footer() ; )
- 其他子產品檔案使用同樣的函數即可應用該子產品
在使用搜尋框的時候,可以封裝一個搜尋框的子產品(就像一個自定義的封裝好的按鈕、表格或者其他元件),使用PHP導入函數,将另外一個檔案的PHP代碼完全導入到本子產品闆即可使用:include(src)
2、窗體化側邊欄
在WordPress就封裝好很多側邊欄的小工具,可以手動在側邊欄div中引用函數展示出來,也可以使用背景管理者視窗對小工具進行管理
- 在側邊欄内容的外面加入函數标記側邊欄的地方:
<?php if ( function_exists('dynamic_sidebar') && dynamic_sidebar() ) : else : ?>
<?php endif; ?>
- 在function.php中加入代碼:
<?php
if ( function_exists('register_sidebar') )
register_sidebar();
?>
- 傳回背景管理的小工具頁面,即可以通過視窗管理側邊工具欄
3、自定義子模闆檔案
建立
single.php 日志單頁檔案
page.php 頁面檔案
archvie.php 分類和日期存檔頁檔案
search.php 搜尋頁面檔案
comments.php 留言區域檔案(包括留言清單和留言框)
404.php 404錯誤頁面
并且通過相應URL的通路,會進入到不同頁面
- 複制index.php頁面到single.php 日志單頁檔案,當點選某個日志的URL就會進入single.php 頁面内容,通過擷取本頁面的日志可以展示本頁面的日志檔案
- 建立404.php頁面,當輸入的URL,與WordPress的路由規則比對不上,會跳轉到該頁面。