Say I have a file named content-header.php
and content-body.php
.
In content-header.php I have this variable:
$some_var = 'apples';
and in content-body.php I have a variable with the same name but different value:
$some_var = 'bananas';
In another file I use:
get_template_part('content', 'header');
get_template_part('content', 'body');
Would $some_var
be limited to its own file or overwrite the other? Is it ok to use same variable names in files added through get_template_part()
?
Would I have to use unique variable names?
Say I have a file named content-header.php
and content-body.php
.
In content-header.php I have this variable:
$some_var = 'apples';
and in content-body.php I have a variable with the same name but different value:
$some_var = 'bananas';
In another file I use:
get_template_part('content', 'header');
get_template_part('content', 'body');
Would $some_var
be limited to its own file or overwrite the other? Is it ok to use same variable names in files added through get_template_part()
?
Would I have to use unique variable names?
Share Improve this question asked Jun 5, 2019 at 20:16 at least three charactersat least three characters 33712 silver badges28 bronze badges1 Answer
Reset to default 3You can absolutely use the same variable names. Arguments like that do not pass through from one template to another without a little help from a function.
So if in content-header.php
you have $fruit = banana;
and in content-body.php
you have $fruit = apple;
you will not have a conflict. Go nuts. Or bananas. ;)
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745433686a4627510.html
评论列表(0条)