dongliu8559 2015-10-20 16:53
浏览 29
已采纳

Wordpress:尝试在窗口小部件定义中调用get_permalink - 抛出错误

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?

  • 写回答

1条回答 默认 最新

  • douna2014 2015-10-20 18:42
    关注

    I tested your code, it was outputting parse error "unexpected var"

        Parse error: syntax error, unexpected 'var' (T_VAR) 
    

    I remove var keyword in front of your variables and it worked:

     $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. As I tested it provided me the link for the page with the slug I provided.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 simulink单相桥式整流电路
  • ¥35 问问51单片机流水灯的代码该怎么写
  • ¥15 关于#百度#的问题:感觉已经将字体段落、字体、页边距、纸张大小、文档网络调成与论文模板一致,为什么黄色部分字体左右的间距还是不一样啊,求私信发文件接收看一下
  • ¥15 stata webuse报错
  • ¥15 TypeError: Cannot read properties of undefined (reading 'status')
  • ¥15 如何利用AI去除图片中的竹架子
  • ¥15 python 写个基金爬取的代码,自动卖出功能
  • ¥15 Linux系统启动不起来
  • ¥15 为什么运行仿真数码管不亮(语言-c语言)
  • ¥15 陈仁良《直升机飞行动力学》小扰动线化方程如何推导