几个常用WordPress主题模板调用的方式

如果我们有在开发WordPress主题的时候,一个页面中会拆分不同的模块组,比如头部、底部、侧边等。那这些拆分的模块如何引用调用呢?这里有几个模板开发的时候调用方式。

1、固定格式

这里头部顶部的固定格式。

get_header(); //引入头部文件header.php

get_footer(); //引入底部文件footer.php

get_sidebar(); //引入侧边栏sidebar.php

2、自定义函数

get_header(‘list’); //调用header-list.php文件

get_footer(‘list’); //调用footer-list.php文件

get_sidebar(‘list’); //调用sidebar-list.php文件

3、引用函数

如果我们将模板放在不同的目录。

get_template_part( $slug, $name );

采用引用模式。

get_template_part( ‘content/head’, ‘list’ );

引用的是 content/head-list.php文件。

投票 post
© 版权声明
THE END
喜欢就支持一下吧
点赞9 分享