我正在嘗試創建一個查詢,以按字母順序顯示分類中的所有術語。使用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