致命错误:调用未定义的函数get_header()

时间:2016-01-03 12:11:09

标签: php wordpress function header undefined

我正在使用此代码转到页面。在我的目录中 有主题文件夹ch。

<li>
<a href="<?php echo get_stylesheet_directory_uri(); ?>/ch/bn1.php">
    <img src="<?php echo get_stylesheet_directory_uri(); ?>/img/bn1.png">
</a>
</li>

但是转到页面网址wp-content / themes / live / ch / bn1.php会显示此消息

  

致命错误:在第1行的C:\ wamp \ www \ blog \ wp-content \ themes \ live stream \ ch \ bn1.php中调用未定义的函数get_header()

我的主题目录是

www/blog/wp-content/themes/live stream

我要转到该目录的页面是

www/blog/wp-content/themes/live stream/ch/bn1.php

1 个答案:

答案 0 :(得分:5)

您正在调用该文件,但您没有加载其余的WordPress。因此get_header()不存在。

WordPress不会像你在这里尝试使用它那样工作。您应该创建一个页面模板,然后使用此模板在WordPress管理员中创建一个页面,然后链接到将在页面编辑屏幕中显示的页面URL。您不能直接链接到模板。

要创建页面模板,请使用WordPress方式尝试阅读https://developer.wordpress.org/themes/template-files-section/page-template-files/