简体   繁体   English

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

[英]get_permalink not working in WordPress template file

I an newbie in PHP and I have the following in a template file.我是 PHP 新手,模板文件中有以下内容。

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

But the above line gives me an error ..但是上面那行给了我一个错误..

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

I tried including the file link-template at the top by using the below line but it doesn't find the file either.我尝试使用以下行在顶部包含文件link-template ,但它也找不到该文件。

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

I googled but everyone seems to have it working .. those who complained were having typos in the function name which are not my cases.我用谷歌搜索,但似乎每个人都在工作..那些抱怨的人在函数名称中有错别字,这不是我的情况。

Any help will be appreciated.任何帮助将不胜感激。 Thanks.谢谢。

I know this is a very old post.我知道这是一个很老的帖子。 But posting if anyone comes looking for answers like me.但是,如果有人像我一样来寻找答案,请发帖。

After requiring, wp-load.php add below,要求后, 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';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM