How to create a recent posts widget that displays category icons

As there is no filter in the recent posts widget, its class must be extended to modify it. I’ve just copied/pasted the original widget() function of the WordPress Recent Posts widget and added the lines 34 to 36. Here is the code that you can paste in functions.php of your theme folder :

Class Caticons_Posts_Widget extends WP_Widget_Recent_Posts {

	function widget($args, $instance) {

		$cache = wp_cache_get('widget_recent_posts', 'widget');

		if ( !is_array($cache) )
			$cache = array();

		if ( ! isset( $args['widget_id'] ) )
			$args['widget_id'] = $this->id;

		if ( isset( $cache[ $args['widget_id'] ] ) ) {
			echo $cache[ $args['widget_id'] ];
			return;
		}

		ob_start();
		extract($args);

		$title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Posts') : $instance['title'], $instance, $this->id_base);
		if ( empty( $instance['number'] ) || ! $number = absint( $instance['number'] ) )
 			$number = 10;
 			
		$r = new WP_Query( apply_filters( 'widget_posts_args', array( 'posts_per_page' => $number, 'no_found_rows' => true, 'post_status' => 'publish', 'ignore_sticky_posts' => true ) ) );
		if ($r->have_posts()) :
?>
		<?php echo $before_widget; ?>
		<?php if ( $title ) echo $before_title . $title . $after_title; ?>
		<ul>
		<?php  while ($r->have_posts()) : $r->the_post(); ?>
		<li><a href="<?php the_permalink() ?>" title="<?php echo esc_attr(get_the_title() ? get_the_title() : get_the_ID()); ?>">
		
		<?php if (function_exists('get_cat_icon_lite')) {
		          echo get_cat_icon_lite();
		      }
		if ( get_the_title() ) the_title(); else the_ID(); ?></a></li>
		<?php endwhile; ?>
		</ul>
		<?php echo $after_widget; ?>
<?php
		// Reset the global $the_post as this query will have stomped on it
		wp_reset_postdata();

		endif;

		$cache[$args['widget_id']] = ob_get_flush();
		wp_cache_set('widget_recent_posts', $cache, 'widget');
	}
}

function caticons_posts_widget_register() {
  unregister_widget('WP_Widget_Recent_Posts');
  register_widget('Caticons_Posts_Widget');
}
add_action('widgets_init', 'caticons_posts_widget_register'); 

Make Category Icons Lite work with Easel

To display icons in front of the title with this theme, Easel, go to Category Icons Lite settings to uncheck Posts. Edit the functions.php file in this theme folder to add these lines at end of the file :

add_filter('easel_display_post_title', 'bm_caticonslite');
function bm_caticonslite($entry_title) {
  return get_cat_icon_lite().$entry_title;
}

Then add this to style.css : Continue reading

Make Category Icons Lite work with any Suffusion based theme

With the Suffusion theme, the icons are not displayed in front of the title. So to make this theme compatible, go to Category Icons Lite settings to uncheck Posts. Edit the functions.php file in this theme folder to add this line in the suffusion_theme_setup() function :

add_filter( 'suffusion_get_post_title_and_link', 'bm_caticonslite' );

Then add this function at the end of the file : Continue reading

Make Category Icons Lite work with any Hybrid based theme

There are some Hybrid based themes that don’t work with Category Icons Lite. For example, Ascetica : the icons are not displayed in front of the title. So to make this theme compatible, go to Category Icons Lite settings to uncheck Posts.

Uncheck Posts

Uncheck Posts

Then, in functions.php in Ascetica theme folder, add this line in the function named ascetica_theme_setup (“theme-name_theme_setup” to be generic) : Continue reading

New version of Category Icons Lite

This version is simpler than the classic one. I’ll put more efforts on this plugin than on the classic one. This is the next generation Category Icons.

It works with more themes than before, example : Prototype or Canvas.

It has an incredibly simple panel settings :

Panel settings

Panel settings

To start using it, just upload your icons (images) via the Media page and assign a category to the image : Continue reading