dongpu3792 2018-06-14 01:56
浏览 81

PHP,Wordpress - get_locale; require_once():需要打开失败

I would appreciate some help with an error I cannot get my head wrapped around...

I migrated a website from my localhost to a server, but now I have one problem with the language translation part.

The code:

<?php
    $locale =get_locale();
    echo $locale;
    $lang = require $_SERVER['DOCUMENT_ROOT'].'/wp-content/themes/template  /lang/$locale.php';
?>

So I echoed the locale to find out if get_locale actually word and it does. it returns "en_US". In the path of require_once this file exists, but if I want to save the file it returns:

Error: require(): Failed opening required '/usr/home/removedusername/htdocs/wp-content /themes/template/lang/$locale.php' (include_path='.:/var/www/php55/lib/php')

While I thought, man the file path must have some problem, I exchanged the "$locale.php" to "en_US.php" and it doesn't show an error and the website actually works also fine just now of course I cannot switch the language anymore as I don't use a variable. Why the path with an included variable ($locale.php) does not work?

Probably a stupid mistake, but I would love some help.

Thank you in advance.

  • 写回答

1条回答 默认 最新

  • dtip91401 2018-06-14 02:04
    关注

    You're using single quotes around your string, so the variable isn't being substituted. Just replace the single quotes with double quotes.

    "$_SERVER[DOCUMENT_ROOT]/wp-content/themes/template/lang/$locale.php"
    

    Note for wordpress, get_template_directory, get_stylesheet_directory, get_theme_root, and plugin_dir_path are available for accessing the configured asset directories.

    评论

报告相同问题?

悬赏问题

  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示