$before_widget, 'after_widget' => $after_widget, 'before_title' => $before_title, 'after_title' => $after_title, 'limit' => $limit, 'flatten' => $flatten, )); } function wp_widget_recent_by_category_control() { $options = $newoptions = get_option('widget_recent_by_category'); if ( $_POST['recent_by_category-submit'] ) { $newoptions['limit'] = $_POST['recent_by_category-limit']; $newoptions['flatten'] = isset($_POST['recent_by_category-flatten']); $newoptions['title'] = strip_tags(stripslashes($_POST['recent_by_category-title'])); } if ( $options != $newoptions ) { $options = $newoptions; update_option('widget_recent_by_category', $options); } $limit = $options['limit']; $flatten = $options['flatten'] ? 'checked="checked"' : ''; $title = attribute_escape($options['title']); ?>

1, 'exclude' => '', 'hdr_level' => '3', 'feed' => '', 'feed_image' => '', 'before_widget' => '', 'after_widget' => '', 'before_title' => '', 'after_title' => '', 'limit' => 5, 'hierarchical' => 1, ); $r = array_merge($defaults, $r); extract($r); $categories = get_categories($r); $output = ''; if ( empty($categories) ) { $output .= $before_widget . __("No categories") . $after_widget; } else { global $wp_query; if( !empty($show_option_all) ) $output .= '' . $show_option_all . ''; if ( is_category() ) $r['current_category'] = $wp_query->get_queried_object_id(); if ( $hierarchical ) $depth = 0; // Walk the full depth. else $depth = -1; // Flat. $output .= rpbc_walk_category_tree($categories, $depth, $r); } return apply_filters('rpbc_recent_posts', $output); } function rpbc_walk_category_tree() { $walker = new Walker_RecentByCategory; $args = func_get_args(); return call_user_func_array(array(&$walker, 'walk'), $args); } class Walker_RecentByCategory extends Walker { var $tree_type = 'category'; var $db_fields = array ('parent' => 'category_parent', 'id' => 'cat_ID'); //TODO: decouple this public $activecats; function start_lvl($output, $depth, $args) { return $output; } function end_lvl($output, $depth, $args) { return $output; } function start_el($output, $category, $depth, $args) { extract($args); if (0 == $depth || ! $flatten) { $output .= $before_widget; $cat_name = attribute_escape( $category->cat_name); $cat_name = apply_filters( 'rpbc_list_cats', $cat_name, $category ); $link = $before_title; $link .= 'category_description) ) $link .= 'title="' . sprintf(__( 'View all posts filed under %s' ), $cat_name) . '"'; else $link .= 'title="' . attribute_escape( apply_filters( 'category_description', $category->category_description, $category )) . '"'; $link .= '>'; $link .= $cat_name . ""; $link .= $after_title; if ( (! empty($feed_image)) || (! empty($feed)) ) { $link .= ' '; if ( empty($feed_image) ) $link .= '('; $link .= ''; $link .= ''; if ( empty($feed_image) ) $link .= ')'; } if ( $current_category ) $_current_category = get_category( $current_category ); $output .= "\t$link\n"; $output .= "

\n"; $output .= $after_widget; } return $output; } } function rpbc_recent_bycat($categories, $args = '') { global $wp_locale, $wpdb; if ( is_array($args) ) $r = &$args; else parse_str($args, $r); $defaults = array('limit' => '', 'format' => 'html', 'before' => '', 'after' => '', ); $r = array_merge($defaults, $r); extract($r); if ( '' != $limit ) { $limit = (int) $limit; $limit = ' LIMIT '.$limit; } $output = ''; ('alpha' == $type) ? $orderby = "post_title ASC " : $orderby = "post_date DESC "; // no idea if this is the most efficient way, but it works ... foreach ($categories as $cat) { $catids[]= $cat->cat_ID; } $choosecat = "( term_taxonomy_id = '" . join("' OR term_taxonomy_id = '", $catids) . "' )"; $arcresults = $wpdb->get_results("SELECT $wpdb->posts.*, $wpdb->term_relationships.term_taxonomy_id FROM $wpdb->posts,$wpdb->term_relationships WHERE post_type = 'post' AND post_status = 'publish' AND object_id = ID AND $choosecat ORDER BY $orderby $limit"); if ( $arcresults ) { foreach ( $arcresults as $arcresult ) { if ( $arcresult->post_date != '0000-00-00 00:00:00' ) { $url = get_permalink($arcresult); $arc_title = $arcresult->post_title; if ( $arc_title ) $text = strip_tags($arc_title); else $text = $arcresult->ID; $output .= get_archives_link($url, $text, $format, $before, $after); } } } return $output; } ?>