0
votes

Ok so I have categories and sub categories to them.

Categories:

Honda

-Civic

-Accord

Toyota

-Camery

-Corrola

Nissan

-Maxima

-Versa

Now I want to display only 5 of those Sub_Categories randomly using wp-list-categories. I went through all of the args but still cant figure this out.

So I would want to see randomly:

  • Versa
  • Civic
  • Camery
  • Maxima
  • Corrola

(with out showing the parent of Honda, Nissan and so forth)

How can this be done? or if it cannot with wp_list_categories then is there a better alternative?

1

1 Answers

0
votes

using get_terms might be a better approach:

// get all terms
$terms = get_terms( 'category' );

// shuffle!
shuffle( $terms );

foreach( array_slice( $terms, 0, 5) as $term ){

    // skip top level terms
    if( 0 == $term->parent )
        continue;

    echo '<a href="' . get_term_link( $term, 'category' ) . '">' . $term->name . '</a>';
}