我正在尝试创建一个查询,以按字母顺序显示分类中的所有术语。使用foreach创建一个按字母顺序显示术语的查询
这里是我的代码,到目前为止,单个字母:
<?php $args = array('name__like' => "a", 'order' => 'ASC');
$terms = get_terms('pa_manufacturer', $args);
if (!empty($terms) && !is_wp_error($terms)) {
$count = count($terms);
$i=0;
$term_list = '<ul class="my_term-archive">';
echo '<h2 class="term-letter">A</h2>';
foreach ($terms as $term) {
$i++;
$term_list .= '<li><a href="' . get_term_link($term) . '" title="' . sprintf(__('View all post filed under %s', 'my_localization_domain'), $term->name) . '">' . $term->name . '</a></li>';
if ($count != $i) {
$term_list .= '';
}
else {
$term_list .= '</ul>';
}
}
echo $term_list;
}
?>
的问题是,目前,我需要手动填写“name__like”的一部分,与H2术语字母一起。
我想在一个查询中返回字母表中的每个字母,动态地更改名称___和h2文本。
否则我需要为每个字母做一个查询,并有25个不完全有效。
我实际上没有太多的运气,所以我希望得到一些建议或帮助。
任何人都可以帮忙吗?
感谢
太棒了,谢谢!我真的很喜欢它:) – 2014-10-10 09:36:31
我的荣幸,很高兴它成为了你。请享用 :-) – 2014-10-10 10:28:33