Thursday, February 7, 2013

How To make a Widget in word press


-->


Hello friend  you can  easily make a simple widget   by the given format
 You  have only to give  you condition  query for the particular data to display from  your data base  or  you can easily set it in your wp side bar by dra and drop .

Code given below is

<?php
/*
Plugin Name: Per Page Post

Description: per page Post widget
Author: Vikas Gautam
Version: 2
Author URI: http://vikasbruce.blogspot.com/
*/

function sampleeventcategory()
{
   $page_name="index.php"; //  If you use this code with a different page ( or file ) name then change this
                                                                $start=$_GET['start'];
                                                                if(strlen($start) > 0 and !is_numeric($start)){
                                                                echo "Data Error";
                                                                exit;
                                                                }
                                                                $eu = ($start - 0);
                                                                $limit = 2;                                 // No of records to be shown per page.
                                                                $this1 = $eu + $limit;
                                                                $back = $eu - $limit;
                                                                $next = $eu + $limit;
                               
         $pname = $_REQUEST['event'];
   

/// here  you have to give your query and   show your date   or call data from data base



And after that you have to put the  code  

function widget_myeventcategory($args) {
  extract($args);

  $options = get_option("widget_myeventcategory");
  if (!is_array( $options ))
{
$options = array(
      'title' => 'My Widget Title'
      );
  }

  echo $before_widget;
    echo $before_title;
      echo $options['title'];
    echo $after_title;

    //Our Widget Content
    sampleeventcategory();
  echo $after_widget;
}

function myeventcategory_control()
{
  $options = get_option("widget_myeventcategory");
  if (!is_array( $options ))
{
$options = array(
      'title' => 'My Widget Title'
      );
  }

  if ($_POST['myeventcategory-Submit'])
  {
    $options['title'] = htmlspecialchars($_POST['myeventcategory-WidgetTitle']);
    update_option("widget_myeventcategory", $options);
  }

?>

  <p>
    <label for="myeventcategory-WidgetTitle">Widget Title: </label>
    <input type="text" id="myeventcategory-WidgetTitle" name="myeventcategory-WidgetTitle" value="<?php echo $options['title'];?>" />
    <input type="hidden" id="myeventcategory-Submit" name="myeventcategory-Submit" value="1" />
  </p>
<?php
}

function myeventcategory_init()
{
  register_sidebar_widget(__(' per page Post '), 'widget_myeventcategory');
  register_widget_control(   ' per page Post ', 'myeventcategory_control', 300, 200 );
}
add_action("plugins_loaded", "myeventcategory_init");
?>

1 comment:

  1. function is_this_mobile()
    {
    if(preg_match('/(alcatel|amoi|android|avantgo|blackberry|benq|cell|cricket|docomo|elaine|htc|iemobile|iphone|ipad|ipaq|ipod|j2me|java|midp|mini|mmp|mobi|motorola|nec-|nokia|palm|panasonic|philips|phone|playbook|sagem|sharp|sie-|silk|smartphone|sony|symbian|t-mobile|telus|up\.browser|up\.link|vodafone|wap|webos|wireless|xda|xoom|zte)/i', $_SERVER['HTTP_USER_AGENT']))
    return true;

    else
    return false;
    }


    $mobilephone = is_this_mobile();

    if($mobilephone === true) {
    echo "yes";
    }
    else
    {
    echo "No";
    }

    ReplyDelete