WordPress函数 set_query_var 与 get_query_var 需配对使用,一个设置参数,一个获取参数。
WordPress 官方给出的示例如下:
// When calling a template with get_template_part()
set_query_var('my_form_id', 23);
get_template_part('my-form-template');
// Inside my-form-template.php
$my_form_id = get_query_var('my_form_id');
使用起来比较简单,但是这对函数的要旨尚未能领悟,貌似也是为了支持主题的结构……
另一个示例:
$sample = 'a sample variable';
$year = 2019;
$arr = [
'sample' = $sample,
'year' = $year
];
set_query_var( 'multiVar', $arr );
get_template_part( 'b' );
get_template_part( 'c' );
在 b.php 文件
$arr = get_query_var( 'multiVar' );
echo $arr['year']; // This will print out: 1995
在 c.php 文件
$arr = get_query_var( 'multiVar' );
echo $arr['sample']; // This will print out: a sample variable
-
WordPress函数:get_user_by 根据 id/slug/email/login 查询用户如何根据用户 slug 查询用户信息?
-
WordPress函数:get_template_part 用法简介get_template_part 有什么优点
-
WordPress函数:wp_is_writable 判断路径是否可写检查文件权限的方便函数
-
WordPress函数:wp_title 主题页面标题WordPress 页面标题SEO
-
WordPress函数:wp_timezone_string 返回后台设置的时区当前设置的时区是什么
-
WordPress函数:current_time 返回当前时间在 WordPress 如何获取当前时间
暂无评论,抢个沙发...