I have this code for index.php
:
<!DOCTYPE html>
<html>
<?PHP
if(isset($_GET['page'])){
require dirname(__FILE__).'/modules/'.$_GET['page'].'/main.php';
} else {
require dirname(__FILE__).'/modules/home.php';
}
?>
</html>
main.php:
$title = 'title test';
$description = 'desc test';
$keyword = 'keys test';
echo _is_header_();
header function:
function _is_header_(){
require ABSPATH.'/templates/'.TEMPLATENAME.'/header.php';
}
In header.php I have meta html tag for title
and echo $title
for show title of page. but I see this error :
<b>Notice</b>: Undefined variable: title in
how do fix this error?!
NOTE: when I replace require ABSPATH.'/templates/'.TEMPLATENAME.'/header.php';
with echo _is_header_();
my code worked true and show my title.
答案 0 :(得分:1)
In your script
ABSPATH.'/templates/'.TEMPLATENAME.'/header.php';
write a
global $title;
just befor the line you use it first time.
答案 1 :(得分:0)
如果您的文件&#34; header.php&#34;操纵变量&#34; $ title&#34;或者她不存在,那么你先打印她,然后才能包含这个文件。