admin 发表于 2020-9-16 00:01:46

destoon送给多城市或开设分站的朋友 城市切换

看到好多站有类似 猜您可能在西安, 点击进入西安站>>
如图:


所有搞了类似一个小功能,希望对需要的哥们AND妹妹有用。

第一步 ->在 extend.func.php 内加入以下函数
<li style="box-sizing: border-box; word-break: break-all; text-size-adjust: none; margin-left: 0px; list-style: none;">function get_ip2city($ip){
</li><li style="box-sizing: border-box; word-break: break-all; text-size-adjust: none; margin-left: 0px; list-style: none;">      global $db;
</li><li style="box-sizing: border-box; word-break: break-all; text-size-adjust: none; margin-left: 0px; list-style: none;">      $city = ip2area($ip);
</li><li style="box-sizing: border-box; word-break: break-all; text-size-adjust: none; margin-left: 0px; list-style: none;">      if(is_array($all_city = cache_read('allcity.php'))){
</li><li style="box-sizing: border-box; word-break: break-all; text-size-adjust: none; margin-left: 0px; list-style: none;">                foreach($all_city as $k => $v){
</li><li style="box-sizing: border-box; word-break: break-all; text-size-adjust: none; margin-left: 0px; list-style: none;">                        $v['name'] = str_replace(array("市","区"," "),array("","",""),$v['name']);
</li><li style="box-sizing: border-box; word-break: break-all; text-size-adjust: none; margin-left: 0px; list-style: none;">                        if(@strstr($city,$v['name'])){
</li><li style="box-sizing: border-box; word-break: break-all; text-size-adjust: none; margin-left: 0px; list-style: none;">                              return $v;
</li><li style="box-sizing: border-box; word-break: break-all; text-size-adjust: none; margin-left: 0px; list-style: none;">                        }
</li><li style="box-sizing: border-box; word-break: break-all; text-size-adjust: none; margin-left: 0px; list-style: none;">                }
</li><li style="box-sizing: border-box; word-break: break-all; text-size-adjust: none; margin-left: 0px; list-style: none;">      }</li>



第二步 -> api\city.php 的 $lists = array(); 上面添加 以下代码


$xxxx = get_ip2city($DT_IP);



以下我临时用的是一下判断仅供参考,谁有好方法可以回复一下。


<li style="box-sizing: border-box; word-break: break-all; text-size-adjust: none; margin-left: 0px; list-style: none;">// $DT_IP = '113.132.197.181';//本地临时测试的IP,实际使用时删除本行代码。
</li><li style="box-sizing: border-box; word-break: break-all; text-size-adjust: none; margin-left: 0px; list-style: none;">
</li><li style="box-sizing: border-box; word-break: break-all; text-size-adjust: none; margin-left: 0px; list-style: none;">if(get_ip2city($DT_IP)){
</li><li style="box-sizing: border-box; word-break: break-all; text-size-adjust: none; margin-left: 0px; list-style: none;">      $xxxx = get_ip2city($DT_IP);
</li><li style="box-sizing: border-box; word-break: break-all; text-size-adjust: none; margin-left: 0px; list-style: none;">}else{
</li><li style="box-sizing: border-box; word-break: break-all; text-size-adjust: none; margin-left: 0px; list-style: none;">      $xxxx['name'] = $L['allcity'];
</li><li style="box-sizing: border-box; word-break: break-all; text-size-adjust: none; margin-left: 0px; list-style: none;">      $xxxx['domain'] = $xxxx['areaid'] = $xxxx['style'] = '';
</li><li style="box-sizing: border-box; word-break: break-all; text-size-adjust: none; margin-left: 0px; list-style: none;">}</li>



第三步 -> 在模版文件 city.htm 文件中 想添加的部分添加模版代码 高手可以无视模版代码


[*]
[*]<li style="box-sizing: border-box; word-break: break-all; text-size-adjust: none; margin-left: 0px; list-style: none;"><!--[ $xxxx 变量自行取名 我这里就用 xxxx 代替了 ]-->
</li><li style="box-sizing: border-box; word-break: break-all; text-size-adjust: none; margin-left: 0px; list-style: none;"><a href="{if $xxxx}{$xxxx}{else}javas<span style="box-sizing: border-box; word-break: break-all; text-size-adjust: none;">cript:gocity('areaid={$xxxx}');{/if}">
</span></li><li style="box-sizing: border-box; word-break: break-all; text-size-adjust: none; margin-left: 0px; list-style: none;">      点击进入{set_style($xxxx, $xxxx)}站
</li><li style="box-sizing: border-box; word-break: break-all; text-size-adjust: none; margin-left: 0px; list-style: none;"></a></li>
[*]





<li style="box-sizing: border-box; word-break: break-all; text-size-adjust: none; margin-left: 0px; list-style: none;"><!--[ $xxxx 变量自行取名 我这里就用 xxxx 代替了 ]-->
</li><li style="box-sizing: border-box; word-break: break-all; text-size-adjust: none; margin-left: 0px; list-style: none;"><!--[ {if $xxxx}代码段{/if} 判断当前城市是否开通了分站的,高手可以无视模版代码 ]-->
</li><li style="box-sizing: border-box; word-break: break-all; text-size-adjust: none; margin-left: 0px; list-style: none;">{if $xxxx}
</li><li style="box-sizing: border-box; word-break: break-all; text-size-adjust: none; margin-left: 0px; list-style: none; font-family: Monaco, Consolas, " lucida="" console",="" "courier="" new",="" serif;="" font-size:="" 12px;="" color:="" rgb(51,="" 102,="" 153);="" background-image:="" initial;="" background-position:="" background-size:="" background-repeat:="" background-attachment:="" background-origin:="" background-clip:="" initial;"=""><a href="{if $xxxx}{$xxxx}{else}javas<span style="box-sizing: border-box; word-break: break-all; text-size-adjust: none;">cript:gocity('areaid={$xxxx}');{/if}">
</span></li><li style="box-sizing: border-box; word-break: break-all; text-size-adjust: none; margin-left: 0px; list-style: none;">      点击进入{set_style($xxxx, $xxxx)}站
</li><li style="box-sizing: border-box; word-break: break-all; text-size-adjust: none; margin-left: 0px; list-style: none;"></a>
</li><li style="box-sizing: border-box; word-break: break-all; text-size-adjust: none; margin-left: 0px; list-style: none;">{/if}</li>


页: [1]
查看完整版本: destoon送给多城市或开设分站的朋友 城市切换