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

此代码将货币切换器添加到菜单中,


但不幸的是我无法访问 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>';


        }

    }

}

?>

但这不起作用?我做错了什么?


慕尼黑的夜晚无繁华
浏览 71回答 1
1回答

慕桂英4014372

你在这里有很多失败:首先,正如@kerbh0lz提到的,“=”和“==”的目的不同。这里你的是错的。其次,如果你的第二种货币是第一种货币,那么它永远不会过去。第三,您正在比较不带引号的字符串或之前不带 $ 的 var,data-currency-code因此您应该使用$currency_code尝试这个:foreach ($supported_currencies as $currency_code) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo '<li data-currency-code="' . $currency_code . '">' . $currency_code . '</li>';&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ($currency_code =='EUR')&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo '<img src="images/euro-flag.png"';&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; elseif ($currency_code == 'TR')&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo '<img src="images/turkish-flag.png"';&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }
打开App,查看更多内容
随时随地看视频慕课网APP