如果我們有在開(kāi)發(fā)WordPress主題的時(shí)候,一個(gè)頁(yè)面中會(huì)拆分不同的模塊組,比如頭部、底部、側(cè)邊等。那這些拆分的模塊如何引用調(diào)用呢?這里有幾個(gè)模板開(kāi)發(fā)的時(shí)候調(diào)用方式。
1、固定格式
這里頭部頂部的固定格式。
get_header(); //引入頭部文件header.php
get_footer(); //引入底部文件footer.php
get_sidebar(); //引入側(cè)邊欄sidebar.php
2、自定義函數(shù)
get_header(‘list’); //調(diào)用header-list.php文件
get_footer(‘list’); //調(diào)用footer-list.php文件
get_sidebar(‘list’); //調(diào)用sidebar-list.php文件
3、引用函數(shù)
如果我們將模板放在不同的目錄。
get_template_part( $slug, $name );
采用引用模式。
get_template_part( ‘content/head’, ‘list’ );
引用的是 content/head-list.php文件。
評(píng)論