【问题标题】:Wordpress custom template issueWordpress 自定义模板问题
【发布时间】:2013-08-27 09:57:48
【问题描述】:

我正在尝试将自定义模板添加到我的 Wordpress 主题中,这将是静态的“关于”页面模板。我在我的第二十二个文件夹中创建 about.php 文件并放入如下内容:

<?php get_header(); ?>

blah blah page content

<?php get_footer(); ?> 

当我在浏览器中打开此文件时,出现错误“致命错误:在第 2 行的 *site_folder_name*\wp-content\themes\twentytwelve\about.php 中调用未定义函数 get_header()”。

我该如何解决这个问题?

【问题讨论】:

  • 做对了吗? Wordpress 不知道您的文件,因此没有 require 语句,因此您的 php 不知道这些功能
  • 你不想直接在浏览器中打开文件,还想通过Wordpress打开资源。
  • 那么,我怎样才能让 wordpress 识别我的页面呢?

标签: php wordpress


【解决方案1】:

首先在您的页面代码顶部添加一个模板名称:

<?php
/* 
 * Template Name: About Page
 */

所以在 wordpress 仪表板中:pages -> your page -> 点击 quick edit 并选择 About Page 模板作为您的页面模板。

阅读更多关于 Page Templates 在 wordpress codex 中的信息:http://codex.wordpress.org/Page_Templates

【讨论】:

  • 非常感谢!这有帮助!
【解决方案2】:

我认为你应该从最小的 wordpress 模板开始,这样你才能掌握它。

这方面有一个很好的教程:

http://www.siteground.com/tutorials/wordpress/wordpress_create_theme.htm

我认为,您遇到的问题是因为您正在使用所有自己的附加代码编辑现有模板。

【讨论】:

    猜你喜欢
    • 2011-11-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-14
    相关资源
    最近更新 更多