需要帮助将php变量插入URL字符串

时间:2019-09-12 19:35:50

标签: php variables

这是我的php文件:

<div id="map_wrap">
    <div id="map"></div>
</div><!-- #map_wrap -->

<?php
$states_list = get_state_list();
$states_to_disable = get_field( 'states_to_disable' );
?>


<ul class="state-list">
    <?php
    foreach( $states_list as $key => $value ){
        $anchor = $key;
        $class = '';
        foreach( $states_to_disable as $state ){
            if( $state['value'] === $key ){
                $class = 'disabled';
                $anchor = 'no-service';
            }
        }
        $anchor = str_replace("_","-",$anchor);
        ?>
        <li><a class="<?= $class; ?>" href="<?php echo site_url(); ?>/<?= $anchor; ?>-quick-online-installment-loans"><?= $value; ?></a></li>
    <?php
    }
    ?>
</ul>


<?php

?>


<script src='<?php echo get_stylesheet_directory_uri(); ?>/js/raphael-min.js'></script>
<script src='<?php echo get_stylesheet_directory_uri(); ?>/js/usmap.js'></script>
<script>
$(document).ready(function() {
    var clickGo = true;
    $('#map').usmap({
        stateStyles: {fill: '#009a4d','stroke': '#ffffff'},
        stateSpecificStyles: {
            <?php
            foreach( $states_to_disable as $state ){
                echo $state['value'] . ": {fill: '#C5C5C5'},";
            }
            ?>
        },
        stateSpecificLabelBackingHoverStyles: {
            <?php
            foreach( $states_to_disable as $state ){
                echo $state['value'] . ": {fill: '#888'},";
            }
            ?>
        },

        clickState: {
            <?php
            foreach( $states_to_disable as $state ){
            ?>
                '<?= $state['value']; ?>' : function(event, data) {
                    var state_name = data.name;
                    console.log('1');
                    clickGo = false;
                    state_name = state_name.replace("_","-")+'';
                    location.href = "<?php echo site_url(); ?>/state-terms-and-rates/no-service";
                },
            <?php
            }
            ?>
        },

        click: function(event, data) {
            var state_name = data.name;
            console.log('2');
            state_name = state_name.replace("_","-")+'';
            if( clickGo === true ){
                location.href = "<?php echo site_url(); ?>/state-terms-and-rates/"+state_name;
            }

        },

            });
});
</script>




正如您所看到的,在代码的最后一部分中,地图上所有被单击的活动状态都转到/ state-terms-and-rates / + state_name。但是,我需要它去/ + state_name-quick-online-installation-loans。

我可以很接近它,但是URL会显示空白的状态名称,单词数组,零或加号,这取决于我尝试的不同方法。

有人可以给我正确的方向吗?

0 个答案:

没有答案
相关问题