此代码用于在类别页面中显示子类别
我需要查看子类别按id排序子类别扫描任何人更新此代码以查看子类别按id排序
<?php
if(is_category()) {
$breakpoint = 0;
$thiscat = get_term( get_query_var(\'cat\') , \'category\' );
$subcategories = get_terms( \'category\' , \'parent=\'.get_query_var(\'cat\') );
$items=\'\';
if(!empty($subcategories)) {
foreach($subcategories as $subcat) {
if($thiscat->term_id == $subcat->term_id) $current = \' current-cat\'; else $current = \'\';
$items .= \'
<span class="sidebar_content_morzak"><a href="\'.get_category_link( $subcat->term_id ).\'" title="">\'.$subcat->name.\'</a></span>
\';
}
echo "$items";
}
unset($subcategories,$subcat,$thiscat,$items);
}
?>
SO网友:birgire
如果您想订购id
您可以替换
$subcategories = get_terms( \'category\' , \'parent=\'.get_query_var(\'cat\') );
与
$args=array(
\'parent\'=>get_query_var(\'cat\'),
\'orderby\' => \'id\',
\'order\' => \'ASC\',
);
$subcategories = get_terms( \'category\' , $args);
您可以在此处阅读有关Codex中可用参数的更多信息:
http://codex.wordpress.org/Function_Reference/get_term