treehouse : what would you like to learn today?
Web Design Web Development iOS Development

paginate get_categories ?

  • I can't figure out how to paginate my categories.php. I have this special loop. I have to have it done this way. I am returning three posts and need to get the pagination working to display the rest of the posts

        Here is the full loop
           $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
          //get the child categories and only display 3 posts
    $allcats = get_categories(array('child_of' => get_query_var('cat'), 'number' => 3,'order'=> 'asc', 'paged' =>     $paged)); 
       foreach ($allcats as $cat) : 
       $args = array(
        'category__in' => array($cat->term_id),
       );
    
       $customInCatQuery = new WP_Query($args); 
    
       if ($customInCatQuery->have_posts()) : 
       echo '<div class="menupageContent">';
           //this chunk of code gets the image attached to each child category
          $terms = apply_filters( 'taxonomy-images-get-terms', '' );
          if ( ! empty( $terms ) ) {
          foreach( (array) $terms as $term ) {
                  if($term->term_id == $cat->term_id) {
                    echo wp_get_attachment_image( $term->image_id, 'menu' );
                  }
          }
          }
       //display the title of each child category
       echo '<h3>'.$cat->name.'</h3>';
       echo '<ul>';    
       //this loop gets all the posts assigned to each child category
       while ($customInCatQuery->have_posts()) : $customInCatQuery->the_post(); ?>
    
       <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    
        <?php
        endwhile; 
        echo '</ul></div><!--end menupageContent-->'; 
    
        ?>
    
       <?php else : 
        echo 'No post published in:'.$cat->name;                
        endif; 
        wp_reset_query();
        endforeach; 
    
  • I am using that, it's not working. I will edit the code to show that above

  • Example:

        $customInCatQuery = new WP_Query($args, 'paged=' . get_query_var( 'paged' ) );
    
  • I don't think that will work. I will try it now though. But I can't use the wp_query. The only way I can seem to get the child categories is by using the foreach loop. I just tried using child_of in a wp_query and got nothing back. I tried to remove the foreach $allcats loop above and replace it with wp_query and I got three posts saying "No post published"