php - 需要帮助将 php 变量插入 URL 字符串
问题描述
这是我的 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-installment-loans。
我可以很接近它,但 URL 要么显示空白状态名称、单词数组、零或加号,具体取决于我一直在尝试的不同事情。
任何人都可以给我正确的方向吗?
解决方案
推荐阅读
- linux - 如何找到一个文件,然后将该文件及其内容存储为变量,以便对原始文件运行操作?
- html - 为标签云创建路标样式大纲
- python - Athena 上的 AWS lambda 查询不返回任何内容
- powershell - 如何更新特定 cmdlet 的帮助?
- cordova - 为什么使用 apache cordova 为 android 签名应用程序失败?
- c - 为什么具有递减阶段的冒泡排序不起作用?
- python - 如何在 3D 列表中弹出元素?
- python - 如何在图形(django python)中循环[('A',1),('B',2),('C',4)]这种类型的数据?
- flutter - 如何在flutter中添加ExpansionPanels之间的间隙?
- python - 根据日期列差异过滤熊猫数据框