php - 按州列出 -> 类别 -> 城市
问题描述
我正在尝试获得以下信息:
状态
-医疗保健(类别)
- 城市
---属性 1
---属性 2
我的查询正在努力获得:
状态
-医疗保健(类别)
--属性 1
--属性 2
而且我不知道如何将 City 作为副标题!
这是我的代码:
<h1 style="padding-bottom: 30px; font-weight: 600;">South Carolina</h1>
<?php //start by fetching the terms for the animal_cat taxonomy
$terms = get_terms( 'property-category', array(
'orderby' => 'count',
'hide_empty' => 0
) );
// now run a query for each animal family
foreach( $terms as $term ) {
// Define the query
$args = array(
'post_type' => 'property',
'property-category' => $term->slug,
'meta_query' => array(
array (
'key' => 'state',
'value' => 'SC'
),
array(
'key' => 'available',
'compare' => '=',
'value' => '1'
)
)
);
$query = null;
$query = new WP_Query( $args );
// output the category name in a heading tag
if( $query->have_posts() ) :
echo'<div class="collapsible"> ' . $term->name . ''; echo' <span style="font-size:12px; vertical-align: middle;">(' . $query->post_count . ')</span></div>';
// output the post titles in a list
echo '<ul class="content">';
// Start the Loop
while ( $query->have_posts() ) : $query->the_post(); ?>
<li style="font-size: 12px; list-style: none; text-transform: none; line-height: 30px; padding-left: 15px;" id="post-<?php the_ID(); ?>">
<?php the_field('town'); ?>
// ****THIS IS WHERE I NEED TO SHOW PROPERTIES UNDER CITY???
<ul>
<li style="font-size: 12px; list-style: none; text-transform: none; line-height: 30px; padding-left: 15px;" id="post-<?php the_ID(); ?>">
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</li>
</ul>
</li>
<?php
endwhile;
endif;
echo '</ul>';
// use reset postdata to restore orginal query
wp_reset_postdata();
} ?>
我完全被卡住了,我需要设置另一个查询吗?
编辑
我现在有了这个,它显示了该城市/城镇中每个可用属性列表上方的城市/城镇,但它复制了这样的城市/城镇标题:
医疗保健
索尔兹伯里
--医务室A
夏洛特
--医务室D
索尔兹伯里
--医务室B
夏洛特
--医务室C
这就是我希望它显示的方式:
医疗保健
索尔兹伯里
--医务室A
--医务室B
夏洛特
--医务室D
--医务室C
这是我的代码:
<div id="sidebar1">
<h1 style="padding-bottom: 30px; font-weight: 600; padding-left: 50px;">North Carolina</h1>
<?php //start by fetching the terms for the animal_cat taxonomy
$terms = get_terms( 'property-category', array(
'orderby' => 'count',
'hide_empty' => 0
) );
// now run a query for each animal family
foreach( $terms as $term ) {
// Define the query
$args = array(
'post_type' => 'property',
'property-category' => $term->slug,
'meta_query' => array(
array (
'key' => 'state',
'value' => 'NC'
),
array(
'key' => 'available',
'compare' => '=',
'value' => '1'
)
)
);
$query = null;
$query = new WP_Query( $args );
// output the category name in a heading tag
if( $query->have_posts() ) :
echo'<div class="collapsible G"> ' . $term->name . ''; echo' <span style="font-size:12px; vertical-align: middle;">(' . $query->post_count . ')</span></div>';
// output the post titles in a list
echo '<ul class="content">';
// Start the Loop
while ( $query->have_posts() ) : $query->the_post(); ?><?php endwhile;
echo '<ul style="margin-left: 0;">';
// Start second Loop
$args = array(
'post_type' => 'property',
'meta_query' => array (
array (
'key' => 'state',
'value' => 'NC',
),
array(
'key' => 'town',
)
)
);
while ( $query->have_posts() ) : $query->the_post(); ?>
<div><?php the_field('town'); ?></div>
<li class="city" id="post-<?php the_ID(); ?>">
<li style="font-size: 15px; list-style: none; text-transform: none; line-height: 30px;" id="post-<?php the_ID(); ?>">
<a class="prop" href="<?php the_permalink(); ?>"><?php the_title(); ?></a> <i class="fas fa-angle-right"></i>
</li>
<?php
endwhile;
endif;
echo '</ul></li></ul>';
// use reset postdata to restore orginal query
wp_reset_postdata();
} ?>
</div>
我究竟做错了什么?
解决方案
推荐阅读
- javascript - 我按下移动键的次数越多,动画的速度就越快。我怎样才能减慢它或逐渐增加它?
- typescript - 打字稿:间接调用函数表达式(iife)中的函数重载?
- laravel - 将 laravel 项目设置为 Nginx 反向代理
- reactjs - 如何在固定布局中渲染不同的组件
- rest - 我应该在restful api中使用不同的satus代码,而不是200吗?
- javascript - [Vue 警告]:渲染错误:“TypeError:无法读取未定义的属性‘audioFiles’
- r - cbind R中的数据框列表
- android - (在 RecyclerView 适配器中)如何在返回同一个 Activity 时完全停止和启动一个 Activity?
- docker - OpenShift - 创建新应用程序时何时创建服务?
- php - 如何在选择少数参数时显示多个高图并使用 PHP 页面动态加载 JSON 数据?