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函数:translate_nooped_plural 翻译并注册字符串WordPress函数:translate_nooped_plural 翻译并注册字符串
-
WordPress函数:number_format_i18n 数字国际化WordPress函数:number_format_i18n 数字国际化
-
WordPress函数:date_i18n 日期国际化WordPress函数:date_i18n 日期国际化
-
WordPress函数:esc_html_e 转义翻译的字符串并显示WordPress函数:esc_html_e 转义翻译的字符串并显示
-
WordPress函数:esc_attr_e 属性转义、翻译、显示WordPress函数:esc_attr_e 属性转义、翻译、显示
-
WordPress函数:esc_attr_x 带上下文的转义属性,翻译显示WordPress函数:esc_attr_x 带上下文的转义属性,翻译显示
暂无评论,抢个沙发...