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.

i use the code to view subcategory on category page

<?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 .= '
        <div class="sidebar">
        <span class="sidebar_content"><a href="'.get_category_link( $subcat->term_id ).'" title="">'.$subcat->name.'</a></span>
        </div>';
        }
        echo "$items";
    }
    unset($subcategories,$subcat,$thiscat,$items);
}
?>

the resut of this code

subcategory1

subcategory2

subcategory3

subcategory4

subcategory5

subcategory6

subcategory7

subcategory8

subcategory9

i want the result like this

subcategory1 * subcategory2 * subcategory3 (all three in same line)
subcategory4 * subcategory5 * subcategory6
subcategory3 * subcategory8 * subcategory9

how can i do that thanks

share|improve this question
2  
Please do the readers of your question one big favor: Make it easy for them. Use proper lower- and uppercase letters, write full sentences, etc. Hint: There's an "edit"-button. –  kaiser Feb 18 '13 at 15:35
    
Spellcheckers for the win. Can you explain how this is a WordPress question and not a generic CSS grid system question? –  Tom J Nowell Feb 18 '13 at 16:54

1 Answer 1

up vote 0 down vote accepted

Yea a bit unclear but I think I understand what your trying to achieve. It's displaying that like most likely due to css. You could target it with a CSS3 pseudo-selector

.sidebar a { float: left; }
.sidebar a:nth-child(4n-0) { clear: left; }

OR.. this might work, no promises though because I can't see your css.

if(is_category()) {

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

$items='';
$breakpoint = 1;
if(!empty($subcategories)) {
    $items .= '<div class="sidebar">';
    foreach($subcategories as $subcat) {
        if($thiscat->term_id == $subcat->term_id) $current = ' current-cat'; else $current = '';
        $items .= '<span class="sidebar_content"><a href="'.get_category_link( $subcat->term_id ).'" title="">'.$subcat->name.'</a></span>';
        if($breakpoint %3 != 0 && $breakpoint != count($subcategories) ) {
            $items .= '</div><div class="sidebar">';
        } elseif($breakpoint == count($subcategories)) {
            $items .= '</div>';
        }
        $breakpoint++;
    }
    echo $items;

}
unset($subcategories,$subcat,$thiscat,$items);

}

share|improve this answer
    
thnks for your help :) its solved –  user2075379 Feb 18 '13 at 16:51

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.