我想在一个自定义分类法中列出所有记录,从A或B开始。下面的代码是列出所有字母的所有记录。
下面是列出具有一个自定义分类法的所有记录的代码,其中所有字母都分组。实例
<?php
// Template Name: Store Template
// get all the stores
$stores = get_terms(APP_TAX_STORE, array(\'hide_empty\' => 0, \'child_of\' => 0, \'pad_counts\' => 0, \'app_pad_counts\' => 1));
// get ids of all hidden stores
$hidden_stores = clpr_hidden_stores();
$list = \'\';
$groups = array();
if ($stores && is_array($stores) ) {
// unset child stores
foreach($stores as $key => $value)
if($value->parent != 0)
unset($stores[$key]);
foreach($stores as $store)
$groups[mb_strtoupper(mb_substr($store->name, 0, 1))][] = $store;
if (!empty($groups)) :
foreach($groups as $letter => $stores) {
$old_list = $list;
$letter_items = false;
$list .= "\\n\\t" . \'<h2 class="stores">\' . apply_filters( \'the_title\', $letter ) . \'</h2>\';
$list .= "\\n\\t" . \'<ul class="stores">\';
foreach($stores as $store) {
if (!in_array($store->term_id, $hidden_stores)) {
$list .= "\\n\\t\\t" . \'<li><a href="\' . get_term_link($store, APP_TAX_STORE) . \'">\' . apply_filters(\'the_title\', $store->name). \'</a> (\' . intval($store->count) . \')</li>\';
$letter_items = true;
}
}
$list .= "\\n\\t" . \'</ul>\';
if(!$letter_items)
$list = $old_list;
}
endif;
} else {
$list .= "\\n\\t" . \'<p>\' . __(\'Sorry, but no stores were found.\', \'appthemes\') .\'</p>\';
}
?>