0

I have using following code for displaying sub categories in parent category page. Its displaying all subcategories in a single page. I want to display 10 sub categories per page. Please help me to limit the sub categories in category page.

My Code :

<?php 

$cat = get_query_var('cat');
$categories= get_categories('hide_empty=0&parent='.$cat);

if(!empty($categories)){

echo '<div class="post-listing"><section id="list"><ul>';

foreach ($categories as $categories_item) {

$mycat .= $category->cat_name;
echo $mycat;


        echo '<li>';
        echo '<h2 class="post-box-title"><a href="' . get_category_link( $categories_item->term_id ) . '" title="' . sprintf( __( "%s" ), $categories_item->name ) . '" ' . '>' . $categories_item->name.'</a> </h2> ';
        $terms = apply_filters( 'taxonomy-images-get-terms', '' );
        if ( ! empty( $terms ) ) {
          foreach( (array) $terms as $term ) {
                if($term->term_id == $categories_item->term_id) {
                   print '<div class="post-thumbnail"><a class="thumb" href="' . esc_url( get_term_link( $term, $term->taxonomy ) ) . '">' . wp_get_attachment_image( $term->image_id, 'medium' );
                   echo '</div></a>';
                 }
            }
            echo '<p>'. $categories_item->description; echo '</p></li>';
        }
    }

    echo '</ul></section></div>';
}else {
?>
  • get_categories('hide_empty=0&parent='.$cat); should be get_categories('hide_empty=0&number=10&parent='.$cat); – Chinmoy Kumar Paul Aug 4 '14 at 4:54
1

Try this way :

get_categories('hide_empty=0&number=10&parent='.$cat);

For more reference visit this link

Here number represents :

number

(string) The number of categories to return

  • Is there any reason why you pass arguments as concatenated string and not as an array? Arrays are much easier to read and quicker (there is no need to parse them)... – Krzysiek Dróżdż Mar 10 '18 at 9:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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