我有问题,我需要显示这样的位置:
-国家/地区
--区域
---城市
-国家/地区
--区域
---城市
我有国家和地区,但我不知道如何按地区显示城市。
这是我的代码:`
<?php if(osc_count_countries() > 0 ) { ?>
<div class="box location">
<h3><strong><?php _e("Location", 'bender') ; ?></strong></h3>
<ul>
<?php while(osc_has_countries() ) { ?>
<li><a href="<?php echo osc_country_url( array( 'sCountry' => osc_list_country_code() ) ) ; ?>"><?php echo osc_country_name() ; ?> <em>(<?php echo osc_country_items() ; ?>)</em></a></li>
<?php if (osc_country_name() =='Austria') { ?>
<ul>
<?php View::newInstance()->_erase('regions');
View::newInstance()->_exportVariableToView('regions', Search::newInstance()->listRegions('AT', '>') ) ;
if(osc_count_regions('AT') > 0 ) {
while(osc_has_regions('AT') ) { ?>
<li><a href="<?php echo osc_search_url(array('sRegion' => osc_region_name()));?>"><?php echo osc_region_name() ; ?> <em>(<?php echo osc_region_items() ; ?>)</em></a></li>
<?php } ?>
</ul>
<?php } ?>
<?php } ?>`
请帮助我
最佳答案
您查看过文档中的帮助程序吗?
https://doc.osclass.org/HLocation.php
与列表中的国家和地区非常相似:
<?php if(osc_count_countries() > 0 ) { ?>
<?php while(osc_has_countries()) { ?>
...
<?php } ?>
<?php } ?>
<?php if(osc_count_regions() > 0 ) { ?>
<?php while(osc_has_regions()) { ?>
...
<?php } ?>
<?php } ?>
但是:
<?php if(osc_count_cities() > 0 ) { ?>
<?php while(osc_has_cities()) { ?>
...
<?php } ?>
<?php } ?>
好的,这是完整的代码:
<?php if(osc_count_countries() > 0 ) { ?>
<?php while(osc_has_countries()) { ?>
<li><a href="<?php echo osc_country_url();?>"><?php echo osc_country_name() ; ?> <em>(<?php echo osc_country_items() ; ?>)</em></a></li>
<?php if(osc_count_regions() > 0 ) { ?>
<?php while(osc_has_regions()) { ?>
<li><a href="<?php echo osc_region_url();?>">-<?php echo osc_region_name() ; ?> <em>(<?php echo osc_region_items() ; ?>)</em></a></li>
<?php if(osc_count_cities(osc_list_region_id()) > 0 ) { ?>
<?php while(osc_has_cities()) { ?>
<li><a href="<?php echo osc_city_url();?>">--<?php echo osc_city_name() ; ?> <em>(<?php echo osc_city_items() ; ?>)</em></a></li>
<?php } ?>
<?php } ?>
<?php } ?>
<?php } ?>
<?php } ?>
<?php } ?>
这将加载所有国家>>地区>>城市,例如:
国家
- 地区
- 城市
- 地区
国家
- 地区
- 城市
- 地区
... 这是一堆数据,具体取决于您拥有多少个城市。 因此我建议您改用 Ajax。
/index.php?page=ajax&action=cities®ionId=%
关于php - Osclass 在侧边栏上的显示位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42601830/