How to display limited wordpress categories?

I want limit number of categories that are displaying, problem is that it uses not default wordpress (it uses theme code that I have) code a.k.a names that I don’t know and google does not found.

So for example this code displays all the categories:

Read More
<?php echo cp_create_categories_list( 'dir' ); ?>

How can I limit number of categories that are displaying?

I have tried combine this with default wordpress code:

    <?php
// display 7 random categories
$cats ='';
$categories=get_categories('exclude=' . $GLOBALS[asides_id]);
$rand_keys = array_rand($categories, 7);
foreach ($rand_keys as $key) {
$cats .= $categories[$key]->term_id .',';
}
wp_list_categories('title_li=&include='.$cats);
?>

But I didn’t got any success with it maybe because of lack of knowledge or it simply does not work.

Related posts

Leave a Reply

1 comment

  1. Please update your code like this

    <?php
    // display 7 random categories
    $cats ='';
    $categories=get_categories('posts_per_page=5&exclude=' . $GLOBALS[asides_id]);
    $rand_keys = array_rand($categories, 7);
    foreach ($rand_keys as $key) {
    $cats .= $categories[$key]->term_id .',';
    }
    wp_list_categories('title_li=&include='.$cats);
    ?>