Title: Implementing a widget plugin to PHP
Last modified: August 20, 2016

---

# Implementing a widget plugin to PHP

 *  [mikhuebner](https://wordpress.org/support/users/mikhuebner/)
 * (@mikhuebner)
 * [13 years, 7 months ago](https://wordpress.org/support/topic/implementing-a-widget-plugin-to-php/)
 * I am trying to implement a widget called ‘Widgetize pages’ to display categories
   of different posts on the main page which I am not running static. I need a little
   help on coding this out in PHP. Here is the link to the site, you can kind of
   get the idea of what I am doing through this.
 * [http://www.southwestshadow.com/](http://www.southwestshadow.com/)
 * Any help at all is appreciated. Thanks guys.

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [rajeishkumarngn1](https://wordpress.org/support/users/rajeishkumarngn1/)
 * (@rajeishkumarngn1)
 * [13 years, 7 months ago](https://wordpress.org/support/topic/implementing-a-widget-plugin-to-php/#post-3120554)
 * A Toronto based [Toronto Wedding Limo](http://www.goodtimelimo.ca) service provider.
   Contact for Limo Services in [Toronto Limo Rentals](http://www.goodtimelimo.ca),
   Mississauga, Brampton, Richmond Hill, Oakville, Markham, Scarborough, Milton 
   and George Town.
 *  [samateo](https://wordpress.org/support/users/samateo/)
 * (@samateo)
 * [13 years, 7 months ago](https://wordpress.org/support/topic/implementing-a-widget-plugin-to-php/#post-3120587)
 * I’ve used widgets and [Mini-Loops](http://wordpress.org/extend/plugins/mini-loops/)
   to do something similar.
 * To make this work, your theme would need to be [widgetized](http://codex.wordpress.org/Widgetizing_Themes)
   with an area to drop in x mini-loop widgets that pull posts according to the 
   criteria you set.
 * Tag the posts you create as ‘**news**‘, ‘**featured**‘, ‘**opinion**‘, ‘**a&e**‘,
   etc. Next, drop a mini-loops widget into the section of your theme where you 
   want the specific group of posts to appear. Last, set the criteria for each widget
   to show just that group.
 * ** Put any modifications to your theme in a [child theme](http://codex.wordpress.org/Child_Themes)
   if you’re concerned about changes being overwritten.
 *  Thread Starter [mikhuebner](https://wordpress.org/support/users/mikhuebner/)
 * (@mikhuebner)
 * [13 years, 7 months ago](https://wordpress.org/support/topic/implementing-a-widget-plugin-to-php/#post-3120612)
 * But how do I get this to display on the main index.php? I am lost on how to do
   this because nothing I do seems to work. Implementing a widget code didn’t work
   so I need a PHP code that will allow me to do this.
 *  [samateo](https://wordpress.org/support/users/samateo/)
 * (@samateo)
 * [13 years, 7 months ago](https://wordpress.org/support/topic/implementing-a-widget-plugin-to-php/#post-3120618)
 * in your functions.php, register a widget area with [register_sidebar()](http://codex.wordpress.org/Function_Reference/register_sidebar)
   called from ‘widgets_init’
 *     ```
       function my_widget_area_init() {
       	register_sidebar( array(
       		'name' => 'Home Page Widget Area',
       		'id' => 'my_widget_post_area_id',
       		'before_widget' => '<div>',
       		'after_widget' => '</div>',
       		'before_title' => '<h2>',
       		'after_title' => '</h2>',
       	) );
       }
       add_action( 'widgets_init', 'my_widget_area_init' );
       ```
   
 * Change the ‘id’ to whatever you want. This will create a widget area that shows
   up in **admin** | **appearance** | **widgets**. You can drop your mini-loops 
   widget (or whatever widgets you want to add) into the new area created in your
   admin.
 * Next, you need to tell the html to look for the widget area that matches the 
   id and output any widgets you’ve assigned.
 * In your index.php put this:
 * `if(!dynamic_sidebar('my_widget_post_area_id')) { echo 'nothing to see here';}`
 * Any widgets you’ve added in admin will appear in the new area. So if you add 
   four widgets that each look for a specific type of post e.g. ‘**news**‘, ‘**featured**‘,‘**
   opinion**‘, ‘**a&e**‘, you can fill in the areas with posts that match what you
   currently have on your home page.
 * Set ‘before_widget’, ‘before_title’, etc. or wrap the php in the if statement
   above in section, article, div or whatever html tags and attributes are appropriate
   for your site, and to give it the style you want. You’ve got similar [options with mini-loops](http://wordpress.org/extend/plugins/mini-loops/other_notes/)
   to set before item, add urls, etc.
 * Might be easier to leave the widget styles empty and recreate your current `div
   class="colart"` in the widget itself under the mini-loops format area.
 * ** To use shortcodes in your widgets, you’ll need to have this in your functions.
   php if not already there `add_filter('widget_text', 'do_shortcode');`

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Implementing a widget plugin to PHP’ is closed to new replies.

## Tags

 * [css](https://wordpress.org/support/topic-tag/css/)
 * [html](https://wordpress.org/support/topic-tag/html/)
 * [javascript](https://wordpress.org/support/topic-tag/javascript/)
 * [linking](https://wordpress.org/support/topic-tag/linking/)
 * [pages](https://wordpress.org/support/topic-tag/pages/)
 * [php](https://wordpress.org/support/topic-tag/php/)
 * [widgetize](https://wordpress.org/support/topic-tag/widgetize/)
 * [widgets](https://wordpress.org/support/topic-tag/widgets/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 3 participants
 * Last reply from: [samateo](https://wordpress.org/support/users/samateo/)
 * Last activity: [13 years, 7 months ago](https://wordpress.org/support/topic/implementing-a-widget-plugin-to-php/#post-3120618)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
