为了账号安全,请及时绑定邮箱和手机立即绑定

如果 var=EUR 时回显图像的语句不起作用

如果 var=EUR 时回显图像的语句不起作用

PHP
慕尼黑的夜晚无繁华 2023-10-15 15:00:38
此代码将货币切换器添加到菜单中,但不幸的是我无法访问 MySQL 数据库,所以我无法为每种货币添加图像“标志”,然后执行它们所以我尝试使用if语句。这是我的代码:$currency_switcher_enable = houzez_option('currency_switcher_enable');$is_multi_currency = houzez_option('multi_currency');if( $currency_switcher_enable != 0 && $is_multi_currency != 1 ) {    if (class_exists('FCC_Rates')) {        $supported_currencies = houzez_get_list_of_supported_currencies();        if (0 < count($supported_currencies)) {            $current_currency = houzez_get_wpc_current_currency();            echo '<li class="btn-price-lang btn-price">';                        echo '<form id="houzez-currency-switcher-form" method="post" action="#" class="open">';            echo '<button id="houzez-selected-currency" class="btn dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"><span>' . $current_currency . '</span> <i class="fa fa-sort"></i></button>';            echo '<ul id="houzez-currency-switcher-list" class="dropdown-menu" aria-labelledby="dropdown" style="display:none;">';            foreach ($supported_currencies as $currency_code) {                echo '<li data-currency-code="' . $currency_code . '">' . $currency_code . '</li>';                if (data-currency-code='EUR') {                    echo '<img src="images/euro-flag.png"';                    if (data-currency-code='TR') {                    echo '<img src="images/turkish-flag.png"';                }            }            echo '</ul>';            echo '<input type="hidden" id="houzez-switch-to-currency" name="houzez_switch_to_currency" value="' . $current_currency . '" />';            echo '<input type="hidden" id="currency_switch_security" name="nonce" value="' . wp_create_nonce('houzez_currency_converter_nonce') . '"/>';            echo '</form>';            echo '</li>';        }    }}?>但这不起作用?我做错了什么?
查看完整描述

1 回答

?
慕桂英4014372

TA贡献1871条经验 获得超13个赞

你在这里有很多失败:

  1. 首先,正如@kerbh0lz提到的,“=”和“==”的目的不同。这里你的是错的。

  2. 其次,如果你的第二种货币是第一种货币,那么它永远不会过去。

  3. 第三,您正在比较不带引号的字符串或之前不带 $ 的 var,data-currency-code因此您应该使用$currency_code

尝试这个:


foreach ($supported_currencies as $currency_code) {

                echo '<li data-currency-code="' . $currency_code . '">' . $currency_code . '</li>';

                if ($currency_code =='EUR')

                    echo '<img src="images/euro-flag.png"';

                elseif ($currency_code == 'TR')

                    echo '<img src="images/turkish-flag.png"';

               

            }


查看完整回答
反对 回复 2023-10-15
  • 1 回答
  • 0 关注
  • 69 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信