• Hello,
    I want to limit the numer of showing categories in wp_list_categories. I mean it unlimited but in my template there not enough place to show it all (I have 16 categories, there’s place for 6-7 in the top menu). I’d like to show random categories there, too. But the main point is to limit the number of it. I’ve checked wp_list_categories in WordPress Codex and there’s something about number of it, but I don’t get it at all.
    In my template it looks so:
    <?php wp_list_categories(‘title_li=&exclude=’ . $GLOBALS[asides_id]) ?>

    I hope somebody could help me.
    Best regards,

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    try this:
    <?php wp_list_categories('title_li=&number=7&exclude=' . $GLOBALS[asides_id]) ?>

    I think random categories is not possible with wp_list_categories.

    Thread Starter jeremanu

    (@jeremanu)

    Thanks, it works ?? And about random categories, I think it is possible – I have seen that on one website on wordpress.

    Moderator keesiemeijer

    (@keesiemeijer)

    try it with this:

    <?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);
    ?>
    Thread Starter jeremanu

    (@jeremanu)

    I’m sorry for late response.
    Thank you, it seems to work, I mean it works, but sometimes it shows for example only 3-5 categories. Weird thing.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to limit number of showing categories?’ is closed to new replies.