Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

this code to display subcategories in categories page

i need to view subcategories sort as id subcategories can anyone update this code to view subcategories order by 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);
}

?>
share|improve this question

1 Answer 1

If you want to order by id you can replace

 $subcategories = get_terms( 'category' , 'parent='.get_query_var('cat') );

with

 $args=array(
     'parent'=>get_query_var('cat'),
     'orderby' => 'id', 
     'order' => 'ASC',  
 );
 $subcategories = get_terms( 'category' , $args);

You can read more about the available parameters in the Codex here:

http://codex.wordpress.org/Function_Reference/get_term

share|improve this answer
    
thanks you . its work very good now –  user2075379 Feb 23 '13 at 20:02
    
ok great it worked out for you ;-) –  birgire Feb 23 '13 at 20:29
    
ps: you should consider marking the question as resolved, thanks ;-) –  birgire Mar 7 '13 at 11:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.