Title: [PATCH] Custom widget frontends
Last modified: August 21, 2016

---

# [PATCH] Custom widget frontends

 *  [flynsarmy](https://wordpress.org/support/users/flynsarmy/)
 * (@flynsarmy)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/patch-custom-widget-frontends-1/)
 * I want to display my featured posts with a layout. Below is a patch that lets
   you drop a sovit-featured-post.php file in your theme where you can loop through
   the posts and render however you want.
 * Change
 *     ```
       function widget( $args, $instance )
       {
       	extract( $args );
       	$title = apply_filters( 'widget_title', $instance[ 'title' ] );
       ```
   
 * to
 *     ```
       function widget( $args, $instance )
       {
       	extract( $args );
       	$title = apply_filters( 'widget_title', $instance[ 'title' ] );
   
       	// Display custom widget frontend
       	if ( $located = locate_template( 'sovit-featured-post.php' ) ) {
       		require $located;
       		return;
       	}
       ```
   
 * **Example Usage**
 * Drop _sovit-featured-post.php_ into your theme and add the following:
 *     ```
       <?php
   
       query_posts( 'post_type=' . $instance[ 'post_type' ] . '&showposts=' . $instance[ 'num' ] . '&featured=yes' );
   
       // Don't show this widget if we have no featured posts
       if ( !have_posts() )
       	return;
   
       echo $before_widget;
   
       if ( $title )
       	echo $before_title . $title . $after_title;
   
       echo '<ul>';
       while ( have_posts() ):
       	the_post();
   
       	echo '<li>';
       		the_post_thumbnail();
       	echo '</li>';
       endwhile;
       echo '</ul>';
   
       echo $after_widget;
       ```
   
 * The above is a very simple example of showing a list of featured images using
   your plugin. If no featured images are found, it won’t display the widget at 
   all.
 * [http://wordpress.org/plugins/featured-post/](http://wordpress.org/plugins/featured-post/)

The topic ‘[PATCH] Custom widget frontends’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/featured-post.svg)
 * [Featured Post](https://wordpress.org/plugins/featured-post/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/featured-post/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/featured-post/)
 * [Active Topics](https://wordpress.org/support/plugin/featured-post/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/featured-post/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/featured-post/reviews/)

 * 0 replies
 * 1 participant
 * Last reply from: [flynsarmy](https://wordpress.org/support/users/flynsarmy/)
 * Last activity: [12 years, 7 months ago](https://wordpress.org/support/topic/patch-custom-widget-frontends-1/)
 * Status: not resolved