You Are Here Home > Wordpress

Wordpress

How To Create WordPress Widgets

No need for a huge fancy post, here is a very simple WordPress widget:

You must paste this code into your theme’s functions.php file located at: /wp-content/themes/YOUR_THEME

class My_Simple_Widget {
 
   function control(){
      $data = get_option('My_Simple_Widget_data');
      ?>
         <p><label>Title:</label> <input name="My_Simple_Widget_title" type="text" value="<?php echo $data['title']; ?>" /></p>
         You can have whatever you want here, even a huge form with any kind of form field you want...
      <?php
      if (isset($_POST['My_Simple_Widget_title'])) {
			$data['title'] = attribute_escape($_POST['My_Simple_Widget_title']);
			update_option('My_Simple_Widget_data', $data);
      }
   }
 
   function widget($args) {
		$data = get_option('My_Simple_Widget_data');
		echo $args['before_widget'];
		echo $args['before_title'] .$data['title'] .$args['after_title'];
		echo 'Here you can have whatever you can imagine...';
		echo $args['after_widget'];
   }
 
}
 
wp_register_sidebar_widget('My_Simple_Widget_ID', 'My Simple Widget Title', array('My_Simple_Widget', 'widget'));
wp_register_widget_control('My_Simple_Widget_ID', 'My Simple Widget Title', array('My_Simple_Widget', 'control'));

This widget will show up in your dashboard under Appearance > Widgets and you can add it to your sidebar.

I hope this helps :)

How To Create WordPress Widgets
Comments (1)   Filed under: PHP,Programming,Web Design,Web Development,Wordpress   Posted by: Hamid

WordPress: Display The Empty Categories

Create a folder and call it show-empty-categories and create a file inside this folder called show-empty-categories.php and paste this code in it:

<?php
/*
Plugin Name: Simple Plugin To Show Empty Categories
Plugin URI: http://blog.code-head.com/
Description: Simple Plugin To Show Empty Categories
Author: Hamid Alipour
Version: 1
 
Requires WordPress 2.1 or later.
*/
 
function codehead_widget_categories_show_empty($args) {
	$args['hide_empty'] = 0;
	return $args;
}
 
add_filter('widget_categories_args', 'codehead_widget_categories_show_empty');
 
?>
WordPress: Display The Empty Categories
Comments (0)   Filed under: Wordpress   Posted by: Hamid