SO网友:A.J. Bale
您的部分问题可能是因为您使用的是get_terms()
作用根据the docs for this function:
从4.5.0开始,分类法应该通过$args数组中的\'taxonomy\'参数传递:
$terms = get_terms( array(
\'taxonomy\' => \'post_tag\',
\'hide_empty\' => false,
) );
因此,我们可以重写您的
get_terms()
和
$argv
对于
cells-days
分类法如下:
$argv = array(
\'taxonomy\' => \'cells-days\',
\'orderby\' => \'by_term\',
\'hide_empty\' => false
);
$cells_days_terms = get_terms( $argv );
然后您可以创建另一个
foreach
在第一个
<li>
中的元素
ul.cell-list
(至少这似乎是您试图循环通过的地方
cells-days
):
<ul class="cell-list">
<li>
<?php $i_max = count( $cells_days_terms ); $i = 0; foreach ( $cells_days_terms as $cells_days_term ): $i++; ?>
<span class="cells-days"><?= ( $i < $i_max ? $cells_days_term->name . \', \' : $cells_days_term->name ) ?></span>
<?php endforeach; ?>
</li>
<!-- The other <li> elements here -->
</ul>
另一方面,我建议修改第一部分,在你回音的地方使用HTML,所以当一切都说了算后,你的代码会是这样的:
<?php
$terms = get_terms(\'cell-locations\');
$argv = array(
\'taxonomy\' => \'cells-days\',
\'orderby\' => \'by_term\',
\'hide_empty\' => false
);
$cells_days_terms = get_terms( $argv );
foreach ($terms as $term):
$wpq = array (\'taxonomy\'=>\'cell-locations\',\'term\'=>$term->slug);
$myquery = new WP_Query ($wpq);
$article_count = $myquery->post_count; ?>
<div class="accordionButton">
<h2 class="cellHeader" id="<?= $term->slug ?>">
<?= $term->name ?>
</h2>
</div>
<div class="accordionContent">
<?php if ($article_count): ?>
<ul class="cell_list">
<?php while ( $myquery->have_posts() ) : $myquery->the_post(); ?>
<li class="cell-item">
<ul class="cell-list">
<li>
<?php $i_max = count( $cells_days_terms ); $i = 0; foreach ( $cells_days_terms as $cells_days_term ): $i++; ?>
<span class="cells-days"><?php echo ( $i < $i_max ? $cells_days_term->name . \', \' : $cells_days_term->name ); ?></span>
<?php endforeach; ?>
</li>
<li><?php echo get_post_meta(get_the_ID(), \'_cell_leader\', true); ?> / <?php echo get_post_meta(get_the_ID(), \'_cell_apprentice\', true)?></li>
<li>Get in touch with <a href="mailto:<?php echo get_post_meta(get_the_ID(), \'_cell_leader_email\', true); ?>"><?php echo get_post_meta(get_the_ID(), \'_cell_leader\', true); ?></a></li>
</ul>
</li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
</div>
<?php endforeach; ?>