[英]What's wrong with this if statement which has two elseifs?
这是代码:
<?php if ( $current_language == es-ES ) : ?>
<?php next_post_link( '%link', 'Proyecto Siguiente ' . _x( '', 'next post link', 'twentyten' ) . '' ); ?>
<?php elseif($current_language == zh-TW) : ?>
<?php next_post_link( '%link', '下一個項目 ' . _x( '', 'next post link', 'twentyten' ) . '' ); ?>
<?php elseif($current_language == zh-CN) : ?>
<?php next_post_link( '%link', '下一个项目 ' . _x( '', 'next post link', 'twentyten' ) . '' ); ?>
<?php else : ?>
<?php next_post_link( '%link', 'Next Project ' . _x( '', 'next post link', 'twentyten' ) . '' ); ?>
<?php endif; ?>
由于某种原因,即使lang设置为zh-TW(繁体中文),我仍然会收到“ Proyecto Siguiente”字样。
有什么建议吗?
您没有引用要比较的字符串,因此PHP将其视为常量(不存在)。 由于PHP首先会寻找一个名为es-ES的常量,并且会引发E_NOTICE级错误(未定义的常量),因此它仍然可以工作。 尝试:
if ( $current_language == 'es-ES' )
等等。
$current_language
是否对应于字符串? 如果是这样,则需要引用表达式的右侧,因为当前PHP认为它们是常量。 放弃速记PHP也是一个好主意,但我不想开始争论。
<?php if ( $current_language == "es-ES" ){...
为什么要使用所有这些php打开/关闭标签? 为什么不在字符串周围使用引号? 无论如何,这是您的代码被清理,它应该工作:
<?php
if ( $current_language == 'es-ES' ) {
next_post_link( '%link', 'Proyecto Siguiente ' . _x( '', 'next post link', 'twentyten' ) . '' );
} elseif( $current_language == 'zh-TW' ) {
next_post_link( '%link', '下一個項目 ' . _x( '', 'next post link', 'twentyten' ) . '' );
} elseif( $current_language == 'zh-CN' ) {
next_post_link( '%link', '下一个项目 ' . _x( '', 'next post link', 'twentyten' ) . '' );
} else {
next_post_link( '%link', 'Next Project ' . _x( '', 'next post link', 'twentyten' ) . '' );
}
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.