我根本不懂php。我在wordpress主题中使用了以下代码,但它不起作用。它出什么问题了?
ICL_LANGUAGE_CODE - 返回en或ro(WPML)
<?php
$lang = ICL_LANGUAGE_CODE;
if ($lang == "en" ) {
echo "L<span class="grey">ocal Pioneer</span> <br /> in <span class="grey"> slow fashion</span>";
}
else {
echo "P<span class="grey">ionier local </span> <br /> în<span class="grey"> slow fashion</span>";
}
?>
答案 0 :(得分:4)
问题在于双引号。
使用单引号,这样您就不必转义双引号(使用echo时)
<?php
$lang = ICL_LANGUAGE_CODE;
if ($lang == "en" ) {
echo 'L<span class="grey">ocal Pioneer</span> <br /> in <span class="grey"> slow fashion</span>';
}
else {
echo 'P<span class="grey">ionier local </span> <br /> în<span class="grey"> slow fashion</span>';
}
?>
答案 1 :(得分:1)
您在双引号字符串中使用双引号。
将你的回声改为:
echo "L<span class='grey'>ocal Pioneer</span> <br /> in <span class='grey'> slow fashion</span>";
和
echo "P<span class='grey'>ionier local </span> <br /> în<span class='grey'> slow fashion</span>";
(注意在双引号内使用单引号。)
答案 2 :(得分:1)
你应该更换doble quote arround&#34; grey&#34; 试试这个:
<?php
$lang = ICL_LANGUAGE_CODE;
if ($lang == "en" ) {
echo "L<span class='grey'>ocal Pioneer</span> <br /> in <span class='grey'> slow fashion</span>";
}
else {
echo "P<span class='grey'>ionier local </span> <br /> în<span class='grey'> slow fashion</span>";
}
?>
答案 3 :(得分:0)
问题是由于使用了引号&#34;。
更改
if ($lang == "en" ) {
echo "L<span class='grey'>ocal Pioneer</span> <br /> in <span class='grey'> slow fashion</span>";
}
else {
echo "P<span class='grey'>ionier local </span> <br /> în<span class='grey'> slow fashion</span>";
}
到
if ($lang == "en" ) {
echo "L<span class="grey">ocal Pioneer</span> <br /> in <span class="grey"> slow fashion</span>";
}
else {
echo "P<span class="grey">ionier local </span> <br /> în<span class="grey"> slow fashion</span>";
}