hi,
I have this code in my home.php to display category + category icon.
i was wondering if is possible to select the category randomly?
<?php recent_posts('limit=10&included_cats=538'); ?>
<?php get_cat_icon('link=true&class=myicons&cat=538&description=true'); ?>
tried this but something is not right..
<?php
$min_count=4; //minimum number of posts in term to consider
$taxonomy = 'category';
$param_type = 'category__in';
$term_args=array(
'orderby' => 'name',
'order' => 'ASC',
);
$allterms = get_terms($taxonomy,$term_args);
// only terms that meet our $min_count
if ($allterms) {
$terms=array();
foreach( $allterms as $term ) {
if ($term->count >= $min_count) {
$terms[]=$term;
}
}
}
if ($terms) {
$random = rand(0,count($terms)-1); //get a random number from 0 to number of elements in $terms array
$term=$terms[$random];
$args=array(
"$param_type" => array($term->term_id),
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => -1,
'caller_get_posts'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
recent_posts('limit=10&included_cats=$term');
}
}
wp_reset_query(); // Restore global post data stomped by the_post().
?>