这是一个持续的请求,试图最大化一些代码,以按国家、特定类型和特定区域显示住宿列表。
例如,法国所有住宿的列表,按酒店评级(1,2,3,4,5),然后按地区(巴黎、马赛等)列表将为
-酒店1星级—马赛—酒店1号—酒店2号—巴黎—酒店1号—酒店2号
-酒店2Star等。。等
每个酒店入口都有一个名为“住宿”的自定义贴子。我有3个分类,国家(即法国)、住宿类型(即酒店1星级)、地区(即巴黎)。
在国家页面上列出住宿“生活”,因此国家的价值已经知道。(即$termcountry->名称)
我的代码如下:
$taxonomy2 = \'accomodation-type\';
$termsacc = get_terms("accomodation-type",array(\'orderby\' => \'slug\', \'order\' => \'ASC\'));
foreach ($termsacc as $termaccomodation) {
$taxonomyregion = \'region\';
$termsreg = get_terms("region",array(\'orderby\' => \'slug\', \'order\' => \'ASC\'));
foreach ($termsreg as $termregion) {
$query = array(
\'post_type\' => \'accomodation\',
\'accomodation-type\' =>$termaccomodation->name,
\'country\' =>$termcountry->name,
\'orderby\' => \'title\',
\'order\' => \'ASC\',
\'posts_per_page\' => 48,
\'tax_query\' => array(
array(
\'taxonomy\' => $taxonomyregion,
\'field\' => \'slug\',
\'terms\' => $termregion->name,
\'orderby\' => \'title\',
\'order\' => \'ASC\',
)
)
);
query_posts($query);
$count = 1; //First we set the count to be zeo
if(have_posts() ) {
$termaccomodation->slug = str_replace("%e2%80%98", "", $termaccomodation->slug);
$termaccomodation->slug = str_replace("%e2%80%99", "", $termaccomodation->slug);
if($termregion->name=="General"){
$regionname = "";
}else{
$regionname = " - ".$termregion->name;
}
$id = \'\';
$new_id = ++ $id;
?>
<a name="<?php echo $new_id."-".$termaccomodation->slug."-".$termregion->slug;?>"></a>
<div id="accitem">
<?php echo "<h3>".$termaccomodation->name."".$regionname."</h3>";?>
<?
while (have_posts()) : the_post();
$linkacc = get_custom_field("AccomodationLink");
?>
I do my loop stuff and display the accom list.
then close my loop
<?php endwhile; wp_reset_query();?>
这是可行的,但真的很慢。。。我很确定这不是最好的方式。我可以请教你一下吗?帮助
干杯