[英]Wordpress: Trying to call get_permalink in widget definition - throws error
The commented line below throws an error. 下面的注释行将引发错误。
class Overall_Travel_Times_Widget extends WP_Widget {
var $title = 'Travel Times Widget';
//var $title_link = get_permalink( get_page_by_path( 'delays' ) );
How can I access the standard wordpress functionality from inside the widget definition? 如何从小部件定义中访问标准的wordpress功能?
I tested your code, it was outputting parse error "unexpected var" 我测试了您的代码,它输出解析错误“意外的var”
Parse error: syntax error, unexpected 'var' (T_VAR)
I remove var keyword in front of your variables and it worked: 我删除变量前面的var关键字,它起作用了:
$title = 'Travel Times Widget';
$title_link = get_permalink( get_page_by_path( 'delays' ) );
So after removing 'var' which you have in front of both variables, your code will work fine. 因此,删除两个变量前面的“ var”后,您的代码即可正常工作。 As I tested it provided me the link for the page with the slug I provided.
经过测试,它为我提供了页面链接,其中包含我提供的子弹。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.