├── readme.txt └── widget.php /readme.txt: -------------------------------------------------------------------------------- 1 | === Plugin Name === 2 | Contributors: twodayslate 3 | Donate link: http://zac.gorak.us 4 | Tags: categories, widget, sidebar 5 | Requires at least: 4.0 6 | Tested up to: 5.0.3 7 | Stable tag: 5.0 8 | License: GPLv2 or later 9 | License URI: http://www.gnu.org/licenses/gpl-2.0.html 10 | 11 | Show your site's most recently used categories! 12 | 13 | == Description == 14 | 15 | Widget to display your site's most recent categories. 16 | 17 | Current options: 18 | 19 | * Max number of categories to display 20 | * Title 21 | * Display date 22 | * Icon (if set by [Simple Cateogry Icon](https://wordpress.org/plugins/simple-category-icons/)) 23 | * Display post count 24 | 25 | GitHub: https://github.com/twodayslate/Recent-Categories-Widget 26 | 27 | == Installation == 28 | 29 | Enable the widget in the sidebar 30 | 31 | 1. Upload `widget.php` to the `/wp-content/plugins/` directory 32 | 2. Activate the plugin through the 'Plugins' menu in WordPress 33 | 3. Place `` in your templates 34 | 4. Or add the widget to your dynamic sidebar in the dashboard (Appearance -> Widgets). 35 | 36 | == Frequently Asked Questions == 37 | 38 | = What options are there? = 39 | 40 | You can set the max number of categories to show, the title, display icon, and the date. 41 | 42 | = How can I contribute? = 43 | Feel free to submit an issue or a pull-request on [GitHub](https://github.com/twodayslate/Recent-Categories-Widget). 44 | 45 | = What is the best way to contact you? = 46 | Check out [my website](http://zac.gorak.us) for a list of ways to do just that! 47 | 48 | == Screenshots == 49 | 50 | 1. screenshot-1.png widget shown in sidebar of Twenty Fifteen 51 | 52 | == Changelog == 53 | 54 | = 1.0 = 55 | * Initial Release 56 | 57 | = 1.1 = 58 | * Added support for [Simple Cateogry Icon](https://wordpress.org/plugins/simple-category-icons/) 59 | 60 | = 1.2 = 61 | * Rewrite 62 | * Added post count option 63 | 64 | = 1.3 = 65 | * Added before_title and after_title support 66 | * Bug fixes 67 | 68 | == Upgrade Notice == 69 | 70 | = 1.0 = 71 | First release. 72 | 73 | = 1.1 = 74 | If you want icon support it is recommended that you upgrade. 75 | 76 | = 1.2 = 77 | Rewrite to add post count option 78 | 79 | = 1.3 = 80 | n/a -------------------------------------------------------------------------------- /widget.php: -------------------------------------------------------------------------------- 1 | __( "You site's most recent categories.", 'text_domain' ),) // Args 38 | ); 39 | 40 | } 41 | 42 | /** 43 | * Front-end display of widget. 44 | * 45 | * @see WP_Widget::widget() 46 | * 47 | * @param array $args Widget arguments. 48 | * @param array $instance Saved values from database. 49 | */ 50 | public function widget( $args, $instance ) { 51 | 52 | // get the excerpt of the required story 53 | if ( isset( $instance[ 'max_count' ] ) ) { 54 | $max_count = $instance[ 'max_count' ]; 55 | } 56 | else { 57 | $max_count = 5; 58 | } 59 | 60 | if ( isset( $instance[ 'title' ] ) && !empty($instance['title'] )) { 61 | $title = $instance[ 'title' ]; 62 | } 63 | else { 64 | $title = "Recent Categories"; 65 | } 66 | if ( isset( $instance[ 'display_date' ] ) ) { 67 | $display_date = $instance[ 'display_date' ] ? true : false; 68 | } 69 | if ( isset( $instance[ 'display_icon' ] ) ) { 70 | $display_icon = $instance[ 'display_icon' ] ? true : false; 71 | } 72 | if ( isset( $instance[ 'display_count' ] ) ) { 73 | $display_count = $instance[ 'display_count' ] ? true : false; 74 | } 75 | 76 | //if ( array_key_exists('before_widget', $args) ) echo $args['before_widget']; 77 | 78 | if (array_key_exists('before_widget', $args)) { 79 | echo str_replace('widget_recent_categories_widget', 'widget_recent_categories_widget widget_recent_entries', $args['before_widget']); 80 | } 81 | 82 | $post_args = array( 83 | 'numberposts' => $max_count, 84 | 'offset' => 0, 85 | 'orderby' => 'post_date', 86 | 'order' => 'DESC', 87 | 'post_type' => 'post', 88 | 'post_status' => 'publish', 89 | 'suppress_filters' => true ); 90 | 91 | $recent_posts = get_posts( $post_args ); 92 | 93 | if ( array_key_exists('before_title', $args) ) { 94 | echo $args['before_title']; 95 | } else { 96 | echo '
167 | 170 |
171 | 172 |173 | 176 |
177 |178 | /> 179 | 180 |
181 |182 | /> 183 | 184 |
185 | 186 |187 | /> 188 | 189 |
190 | 191 | 192 |