WordPress.org

Ready to get started?Download WordPress

Forums

Category Icons
[resolved] Random Category Icons in Sidebar (3 posts)

  1. PDXDesigner
    Member
    Posted 3 years ago #

    Hello,

    I was wondering if there was a way to show random category icons in the sidebar. I am using a PHP Widget Box to show the following random categories currently. Is there a way to add the category icons to this code?

    <?php
    // display 10 random categories
    $cats ='';
    $categories=get_categories();
    $rand_keys = array_rand($categories, 10);
    foreach ($rand_keys as $key) {
    $cats .= $categories[$key]->term_id .',';
    }
    wp_list_categories('title_li=&hierarchical=true&hide_empty=0&show_count=1&include='.$cats);
    ?>

    Thanks,
    Steve

  2. PDXDesigner
    Member
    Posted 3 years ago #

    Never Mind. I figured it out.

    If anyone is using the Category Icons Plugin and wants to call the code into a sidebar widget and have it pull random list of 10, use the following code:

    <?php
    $cats ='';
    $categories=get_categories();
    $rand_keys = array_rand($categories, 10);
    foreach ($rand_keys as $key) {
    $cats .= $categories[$key]->term_id .',';
    }
    put_cat_icons(wp_list_categories('title_li=&echo=0&hierarchical=1&hide_empty=0&orderby=name&show_count=1&include='.$cats));
    ?>

    Of course you can change the 10 in the code about to show any number you wish.

  3. submarine
    Member
    Plugin Author

    Posted 3 years ago #

    Hi, thanks for sharing !

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic