How I can break wordpress loop after 6 items and then continue with the rest items

I have a wordpress taxonomy category filter displayed with this code

<?php                               
$video_args = array(                                        
    'hide_empty' => true,                                       
    'fields' => 'all',                                      
    'hierarchical' => true,                     
    'orderby' => 'term_order',                                      
    'child_of' => 0,                                        
    'get' => '',                                        
    'name__like' => '',                                     
    'pad_counts' => false,                                      
    'taxonomy' => 'video-category',                                     
    'cache_domain' => 'core'                                
);      
$coount = 1;
$v_terms = get_terms('video-category', $video_args);    
foreach ($v_terms as $v_term) {                     
    $term_link = get_term_link($v_term, 'video-category'); 
    if($coount < 7){
         ?>                                         
         <li class="video_<?php echo $v_term->term_id; ?>_term" id="<?php echo $coount++ ?>">                               
             <a id="<?php echo $v_term->term_id; ?>"><?php echo $v_term->name; ?></a>                               
             <span class="active_tab_border"></span>                            
         </li>
     <?php } else { ?>
         </ul><li class='restcats'>
         <ul class='restcat_list'>
              <li class="video_<?php echo $v_term->term_id; ?>_term" id="<?php echo $coount++ ?>">                              
                  <a id="<?php echo $v_term->term_id; ?>"><?php echo $v_term->name; ?></a>                              
                  <span class="active_tab_border"></span>                           
              </li>
              </ul>
              </li>
     <?php }

       } $coount++                  
      ?>

I need to break a loop after 6 items and then wrap items starting from 7 to another div and gave another style.With mine code it is not working properly, it created one for each next item.

Related posts

1 comment

  1. Put you items after 7 outside the loop.

    <?php                               
                                $video_args = array(                                        
                                    'hide_empty' => true,                                       
                                    'fields' => 'all',                                      
                                    'hierarchical' => true,                     
                                    'orderby' => 'term_order',                                      
                                    'child_of' => 0,                                        
                                    'get' => '',                                        
                                    'name__like' => '',                                     
                                    'pad_counts' => false,                                      
                                    'taxonomy' => 'video-category',                                     
                                    'cache_domain' => 'core'                                
                                    );      
                                    $coount = 1;
                                $v_terms = get_terms('video-category', $video_args);    
                                foreach ($v_terms as $v_term) {                     
                                    $term_link = get_term_link($v_term, 'video-category'); 
                                    if($coount < 7){
                                    ?>                                          
                            <li class="video_<?php echo $v_term->term_id; ?>_term" id="<?php echo $coount++ ?>">                                
                                <a id="<?php echo $v_term->term_id; ?>"><?php echo $v_term->name; ?></a>                                
                                <span class="active_tab_border"></span>                         
                            </li>
                                <?php  }else{?>
                         <?php if($coount == '7') { ?>  
                         </ul><li class='restcats'>
                               <ul class='restcat_list'>
                          <?php } ?>
    
                                    <li class="video_<?php echo $v_term->term_id; ?>_term" id="<?php echo $coount++ ?>">                                
                                        <a id="<?php echo $v_term->term_id; ?>"><?php echo $v_term->name; ?></a>                                
                                        <span class="active_tab_border"></span>                         
                                    </li>
    
                            <?php if(($coount-1) == count($v_terms)){ ?>
                               </ul>
                            </li>
                            <?php } 
                                 }
    
                                }    $coount++;                  
                                ?>
    

Comments are closed.