我创建了一个列表网站,我在其中使用服务提供商作为自定义帖子类型,将城市和服务用作自定义分类类型,例如类别。现在,我想在城市页面下显示那些服务,将显示哪些服务提供那些城市服务提供商。
$args = array(
'taxonomy' => 'service',
'parent' => 0,
'orderby' => 'name',
'order' => 'ASC',
'hierarchical' => 1,
'hide_empty' => 0,
'pad_counts' =>0
);
$categories = get_categories( $args );
foreach ( $categories as $category ){
echo '<div class="packer-movers">
<div class="container">
<div class="row">';
echo '<h2>' . $category->name . '</h2>';
$cityargs = array(
'taxonomy' => 'city',
'parent' => term_id,
'orderby' => 'name',
'order' => 'ASC',
'hierarchical' => 1,
'hide_empty' => 0,
'pad_counts' => 0
);
$sub_args = array(
'taxonomy' => 'service',
'parent' => $category->term_id,
'orderby' => 'name',
'order' => 'ASC',
'hierarchical' => 1,
'hide_empty' => 0,
'pad_counts' => 0
);
$sub_categories = get_categories( $sub_args );
echo "<div class='children'>";
foreach ( $sub_categories as $sub_category ){
echo '<div class="col-sm-3">
<div class="mvrs">
<div class="mvrs-img">';
if (function_exists('get_wp_term_image'))
{
$meta_image = get_wp_term_image($sub_category->term_id);
}
echo "<img src='$meta_image' class='img-responsive hvr-grow' alt='. $sub_category->name . '>";
echo '<div class="movrs">
<div class="row">
<p class="mvrs-hd">'. $sub_category->name . '</p>
<div class="mvrs-btn">
<button class="get-qut">GET QUOTES</button>
</div>
</div>
</div>';
//echo '<span>'. $sub_category->name . '</span>';
echo "</div>
</div>
</div>";
}
echo "</div>";
echo "</div></div></div>";
}
给我一些参考。