WordPress 函数 get_template_part 和 require 差不多,但是比 require 多两个优点。
一、对子主题的支持。
<?php get_template_part( 'loop', 'index' ); ?>
上述代码,会依次寻找下面的文件。
wp-content/themes/twentytenchild/loop-index.php
wp-content/themes/twentyten/loop-index.php
wp-content/themes/twentytenchild/loop.php
wp-content/themes/twentyten/loop.php
二、可以给文件传入参数。
get_template_part(
'loop',
'index',
array(
'key' => 'value',
'key2' => 'value2'
)
);
在 loop-index.php 中可以使用下面的方式读取参数。
var_dump( $args ); // Everything
echo $args['key']; // Specific values
-
WordPress函数:is_rtl 确定当前区域设置是否为从右到左(RTL)WordPress函数:is_rtl 确定当前区域设置是否为从右到左(RTL)
-
WordPress函数:is_multisite 是否开启了多站点WordPress函数:is_multisite 是否开启了多站点
-
WordPress函数:is_main_site 是否是主站点WordPress函数:is_main_site 是否是主站点
-
WordPress函数:is_child_theme 是否正在使用子主题WordPress函数:is_child_theme 是否正在使用子主题
-
WordPress函数:current_theme_supports 检查主题对给定功能的支持WordPress函数:current_theme_supports 检查主题对给定功能的支持
-
WordPress函数:is_customize_preview 是否在自定义设置程序中预览网站WordPress函数:is_customize_preview 是否在自定义设置程序中预览网站
暂无评论,抢个沙发...