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

ahm*_*her 2 php wordpress header function 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>
Run Code Online (Sandbox Code Playgroud)

但是转到页面url 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
Run Code Online (Sandbox Code Playgroud)

我要转到目录的页面是

www/blog/wp-content/themes/live stream/ch/bn1.php
Run Code Online (Sandbox Code Playgroud)

Jam*_*nes 5

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

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

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