posts as p"; $bfa_pic_request .= " INNER JOIN $wpdb->term_relationships AS tr ON"; $bfa_pic_request .= " (p.ID = tr.object_id AND"; $bfa_pic_request .= " tr.term_taxonomy_id = $cat_id )"; $bfa_pic_request .= " INNER JOIN $wpdb->term_taxonomy AS tt ON"; $bfa_pic_request .= " (tr.term_taxonomy_id = tt.term_taxonomy_id AND"; $bfa_pic_request .= " taxonomy = 'category')"; $bfa_pic_request .= " WHERE post_status = 'publish' AND comment_count >= $bfa_pic_min_amount_comments"; $bfa_pic_request .= " AND post_password =''"; if ($bfa_pic_duration !="") $bfa_pic_request .= " AND DATE_SUB(CURDATE(),INTERVAL ".$bfa_pic_duration." DAY) < post_date "; $bfa_pic_request .= " ORDER BY comment_count DESC LIMIT $bfa_pic_no_posts"; $bfa_pic_posts = $wpdb->get_results($bfa_pic_request); if ($bfa_pic_posts) { foreach ($bfa_pic_posts as $bfa_pic_post) { $bfa_pic_post_title = stripslashes($bfa_pic_post->post_title); $bfa_pic_comment_count = $bfa_pic_post->comment_count; $bfa_pic_permalink = get_permalink($bfa_pic_post->ID); $widget_mdv_most_commented_per_cat .= '
  • ' . $bfa_pic_post_title . ' (' . $bfa_pic_comment_count . ')
  • '; } } else { $widget_mdv_most_commented_per_cat = "None found"; } if ($widget_mdv_most_commented_per_cat != "None found") { echo $before_widget . $before_title . $bfa_pic_title . $after_title; echo ""; echo $after_widget; } else { return $widget_mdv_most_commented_per_cat; } } } // This is the function that outputs the form to let the users edit // the widget's parameters. function widget_mdv_most_commented_per_cat_control() { // Fetch the options, check them and if need be, update the options array $bfa_pic_options = $bfa_pic_newoptions = get_option('widget_mdv_most_commented_per_cat'); if ( $_POST["bfa_pic_src-submit"] ) { $bfa_pic_newoptions['bfa_pic_title'] = strip_tags(stripslashes($_POST["bfa_pic_src-title"])); $bfa_pic_newoptions['bfa_pic_no_posts'] = (int) $_POST["bfa_pic_no_posts"]; $bfa_pic_newoptions['bfa_pic_duration'] = (int) $_POST["bfa_pic_duration"]; $bfa_pic_newoptions['bfa_pic_min_amount_comments'] = (int) $_POST["bfa_pic_min_amount_comments"]; $bfa_pic_newoptions['bfa_pic_append_cat_title'] = !isset($_POST["bfa_pic_append_cat_title"]) ? NULL : $_POST["bfa_pic_append_cat_title"]; $bfa_pic_newoptions['bfa_pic_prepend_cat_title'] = !isset($_POST["bfa_pic_prepend_cat_title"]) ? NULL : $_POST["bfa_pic_prepend_cat_title"]; } if ( $bfa_pic_options != $bfa_pic_newoptions ) { $bfa_pic_options = $bfa_pic_newoptions; update_option('widget_mdv_most_commented_per_cat', $bfa_pic_options); } // Default options to the parameters if ( !$bfa_pic_options['bfa_pic_no_posts'] ) $bfa_pic_options['bfa_pic_no_posts'] = 10; if ( !$bfa_pic_options['bfa_pic_min_amount_comments'] OR $bfa_pic_options['bfa_pic_min_amount_comments'] == 0) $bfa_pic_options['bfa_pic_min_amount_comments'] = 1; $bfa_pic_no_posts = $bfa_pic_options['bfa_pic_no_posts']; $bfa_pic_duration = $bfa_pic_options['bfa_pic_duration']; $bfa_pic_min_amount_comments = $bfa_pic_options['bfa_pic_min_amount_comments']; $bfa_pic_append_cat_title = $bfa_pic_options['bfa_pic_append_cat_title']; $bfa_pic_prepend_cat_title = $bfa_pic_options['bfa_pic_prepend_cat_title']; // Deal with HTML in the parameters $bfa_pic_title = htmlspecialchars($bfa_pic_options['bfa_pic_title'], ENT_QUOTES); ?> Title:

    />Prepend  

    /> Append    Category Name to Title


    Show posts not older than days and with at least  comments