get_permalink在WordPress模板文件中不起作用


get_permalink not working in WordPress template file

我是PHP的新手,我在模板文件中有以下内容。

$url = get_permalink(get_page_by_title('Main'));

但是上面的一行给了我一个错误..

Fatal error: Call to undefined function get_permalink() in C:'wamp'www'wordpress'wp-content'themes'twentysixteen'handleLogin.php

我尝试使用以下行将文件link-template包含在顶部,但它也没有找到该文件。

include_once 'wp-includes/link-template.php';

用谷歌搜索,但每个人似乎都可以工作..那些抱怨的人在函数名称中有错别字,这不是我的情况。

任何帮助将不胜感激。谢谢。

我知道这是一个非常古老的帖子。但是,如果有人像我一样来寻找答案,请发布。

在需要后,wp-load.php在下面添加,

require_once ABSPATH . WPINC . '/class-wp-rewrite.php';
require_once ABSPATH . WPINC . '/link-template.php';
require_once ABSPATH . WPINC . '/post.php';
require_once ABSPATH . WPINC . '/class-wp-post.php';
require_once ABSPATH . WPINC . '/category-template.php';
require_once ABSPATH . WPINC . '/taxonomy.php';
require_once ABSPATH . WPINC . '/l10n.php';
require_once ABSPATH . WPINC . '/formatting.php';