wordpress - 如何为每个自定义分类法回显某些内容?
问题描述
我有一个页面,我想在其中显示各种智能手机的维修价格。我创建了自定义帖子类型“Reparaturpreise”(维修价格)以及自定义分类法“Marken”(品牌)。对于每个品牌,我想将品牌名称显示为标题,下面应该有一个表格,列出各种维修价格。
这是我到目前为止的代码:
<?php
$args = array(
'taxonomy' => 'marke',
'orderby' => 'name',
'order' => 'ASC'
);
$cats = get_categories($args);
foreach($cats as $cat) {
?>
<h2><?php echo strip_tags(get_the_term_list( $post->ID, 'marke', '', ', ' ));?></h2>
<?php
$args = array(
'post_type' => 'reparaturpreise',
'category' => 'apple',
'posts_per_page' => 999
);
$the_query = new WP_Query( $args );
?>
<table class="repair-prices-list">
<tr>
<th>Gerät</th>
<th>Display</th>
<th>Akku</th>
<th>Backcover</th>
</tr>
<?php
if ( $the_query->have_posts() ) :
while ( $the_query->have_posts() ) : $the_query->the_post();
?>
<tr>
<td><?php echo strip_tags(get_the_term_list( $post->ID, 'marke', '', ', ' ));?> <?php the_title(); ?></td>
<td>€ <?php echo get_post_meta($post->ID, 'displayreparatur', true); ?>,-</td>
<td>€ <?php echo get_post_meta($post->ID, 'akkutausch', true); ?>,-</td>
<td>€ <?php echo get_post_meta($post->ID, 'backcover-reparatur', true); ?>,-</td>
</tr>
<?php
wp_reset_postdata();
endwhile;
endif;
?>
</table>
<?php
}
?>
现在它显示了 3 个表格,但都具有相同的标题(第一个品牌),每个表格都显示了所有手机,而不是按品牌过滤。
您可以在此处查看当前输出: https ://relaunch.websolute.at/reparaturpreise/
提前感谢您的帮助,如果我的英语不是最好的,我们深表歉意。
解决方案
目前您有:
<h2><?php echo strip_tags(get_the_term_list( $post->ID, 'marke', '', ', ' ));?></h2>
尝试:
<h2><?php echo strip_tags(get_the_term_list( $post->ID, $cat, '', ', ' ));?></h2>
当您尝试获取不同的猫时。
您也可以更改posts_per_page
为-1
相同的“无限”结果。
推荐阅读
- python - 在 qtableview 中以编程方式更改复选框的状态
- ios - Azure Web App - 当您选择运行时堆栈作为 Node.js 时,为什么它只允许您选择 Linux 作为操作系统?
- python - pandas 如何神奇地选择列来应用布尔索引?
- javascript - 删除数组中的所有重复项和未定义项。Ramda.js
- c# - 我的 Unity 项目中出现了 Microsoft (R) Visual C# 编译器错误
- python - 如何使用 google-api-client 创建实例?
- ios - swift segue new viewcontroller 在后台加载其他任务时卡住
- firebase - Flutter Firebase 我将如何从快照中获取特定数据
- html - 为什么 flexbox 在包装元素后不收缩以适应?
- dll - 无法在 .NET Core 3 中卸载 DLL