\n"; yg_randomposts("limit=$limit&cats=$cats¤tcat=$currentcat"); echo "\n"; echo $after_widget; } function yg_randomposts_options() { $options = get_option('yg_randomposts'); if (!is_array($options)) { $options = array('title' => 'Random Posts', 'entries-number' => '10', 'currentcat' => 0, 'categories' => ''); update_option('yg_randomposts', $options); } if ($_POST['yg-randomposts-submit']) { $options['entries-number'] = intval($_POST['yg-randomposts-entries-number']); if (($options['entries-number'] < 1) || ($options['entries-number'] > 20)) $options['entries-number'] = 10; $options['title'] = strip_tags(stripslashes($_POST['yg-randomposts-title'])); $options['currentcat'] = ($_POST['yg-randomposts-currentcat']) ? 1 : 0; $cats = str_replace(" ", "", strip_tags(stripslashes($_POST['yg-randomposts-categories']))); if (!intval($cats)) $cats=''; $options['categories'] = $cats; update_option('yg_randomposts', $options); } ?>
10, 'cats' => '', 'currentcat' => 0 ); $args = wp_parse_args( $args, $defaults ); extract($args); $limit = intval($limit); $cats = str_replace(" ", "", $cats); if (($limit < 1 ) || ($limit > 20)) $limit = 10; if (($currentcat) && (is_category())) { $cats = get_query_var('cat'); } if (($currentcat) && (is_single())) { $cats = ''; foreach (get_the_category() as $categories) { $cats .= $categories->cat_ID.' '; } $cats = str_replace(" ", ",", trim($cats)); } if (!intval($cats)) $cats=''; if ($cats == '') $sql = "SELECT id, post_title, post_name FROM $wpdb->posts WHERE ((post_status='publish') AND (post_type = 'post') AND ($wpdb->posts.post_password = '')) ORDER BY RAND() LIMIT $limit"; else $sql="SELECT $wpdb->posts.id, $wpdb->posts.post_title FROM $wpdb->posts, $wpdb->term_relationships WHERE $wpdb->posts.post_type = 'post' AND $wpdb->posts.post_status = 'publish' AND $wpdb->posts.post_password = '' and $wpdb->posts.id = $wpdb->term_relationships.object_id and $wpdb->term_relationships.term_taxonomy_id in ($cats) GROUP BY $wpdb->posts.id ORDER BY rand(), $wpdb->posts.post_date desc LIMIT $limit"; $randomposts = $wpdb->get_results($sql); $postlist = ''; foreach ($randomposts as $post) { $post_title = htmlspecialchars(stripslashes($post->post_title)); $postlist .= "