query_var] != 'all'){
$get_posts_args[$tax->query_var] = $instance[$tax->query_var];
$taxonomies_for_count[] = $instance[$tax->query_var];
}
}
//if post type and category, then added to the args of get_post function
if ($post_type == 'all'){
$get_posts_args['post_type'] = 'any';
}else{
$get_posts_args['post_type'] = $post_type;
}
if ($category != 'all'){
$get_posts_args['category_name'] = $category;
}
//before random, have to get total posts
$total_posts = self::__apc_count_posts($post_type, $category, $taxonomies_for_count);
if ( $random ){
$offset = mt_rand(0, $total_posts - 1);
}else{
$offset = 0;
}
$get_posts_args['numberposts'] = $init_posts;
$get_posts_args['offset'] = $offset;
$posts = get_posts($get_posts_args);
self::__display_items($posts, $show_title);
//when the offset is to high and only a few posts (less than init_posts) are displayed, we have to get some more
$new_offset = $offset + $init_posts;
if ( $new_offset > $total_posts && $offset > 0 ){
//shows all the posts needed to complete the init_posts number, but shouldn't repeat the ones already shown
$get_posts_args['numberposts'] = min($new_offset - $total_posts, $offset);
$get_posts_args['offset'] = 0;
$posts = get_posts($get_posts_args);
self::__display_items($posts, $show_title);
}
?>
posts AS p";
foreach($taxonomies_for_count as $key => $termslug){
$SQL .= ", $wpdb->term_relationships AS rel$key, $wpdb->term_taxonomy AS tax$key, $wpdb->terms AS term$key";
}
if ( ! empty($taxonomies_for_count)){
$SQL .= " WHERE p.ID=rel0.object_id";
}
foreach($taxonomies_for_count as $key => $termslug){
if ($key > 0){
$SQL .= " AND p.ID=rel$key.object_id";
}
$SQL .= " AND rel$key.term_taxonomy_id=tax$key.term_taxonomy_id AND tax$key.term_id=term$key.term_id AND term$key.slug='$termslug'";
}
if ( ! empty($taxonomies_for_count)){
$SQL .= " AND p.post_status='publish'";
}else{
$SQL .= " WHERE p.post_status='publish'";
}
if ($post_type != 'all'){
$SQL .= " AND p.post_type='$post_type'";
}
//echo $SQL.' ';
return $wpdb->get_var($SQL);
}
function __display_items($posts, $show_title){
foreach ($posts as $post){
echo '