How to set the limit of the list of categories?

I am showing a message category child list.list show all I need to display only 6 (child) help us ...

for example: menu (parent) list1 (child) list2 (child) list3 (child) list4 (child) list5 (child) list6 (child) list7 (child) list8 (child)

<?php $article_categories = get_categories(array(
                                    'child_of' => get_category_by_slug('work')->term_id
                            ));
    $talentChildren = get_categories(array('child_of' => get_category_by_slug('talent')->term_id));


 ?>
    <?php if ( have_posts()) : ?>
        <?php $talent_Children = array($talentChildren[0]); ?>
        <?php foreach($talent_Children as $talent): ?>
        <?php
        $talentSubChildren = new WP_Query();
        $talentSubChildren->query(array('category_name' => $talent->slug));
        ?>
        <h2><a href="<?php the_permalink() ?>talent/directors/"><?php echo $talent->name; ?></a></h2>
        <ul>
        <?php while ($talentSubChildren->have_posts()) : $talentSubChildren->the_post(); ?>
        <li>
        <h4><a href="<?php the_permalink() ?>"><?php the_title(); ?></a>
        </h4>
        </li>
        <?php endwhile; ?>
        </ul>
        <?php endforeach; ?>
        <?php endif; ?>
        </div>
+4
source share
1 answer

You can specify user number = 6 in the get_categories function, for example

$talentChildren = get_categories(array('child_of' => get_category_by_slug('news')->term_id,'number' => 6,'hide_empty' => 0));
foreach($talentChildren as $talent):
    echo "<pre>";
    print_r($talent);
    echo "</pre>";
endforeach;
+5
source

All Articles