Skip to content

Instantly share code, notes, and snippets.

@isGabe
Created June 17, 2013 20:25

Revisions

  1. isGabe revised this gist Jun 17, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion widgets.php
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@
    /*
    * Basic WordPress Widget Code
    * Save to: /wp-content/theme/widgets.php
    *
    * in functions.php or appropriate place: if ($wp_version >= 2.8) require_once(TEMPLATEPATH.'/widgets.php');
    *
    */
    class MyWidgetName extends WP_Widget
  2. isGabe created this gist Jun 17, 2013.
    50 changes: 50 additions & 0 deletions widgets.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,50 @@
    <?php

    /*
    * Basic WordPress Widget Code
    * Save to: /wp-content/theme/widgets.php
    *
    *
    */
    class MyWidgetName extends WP_Widget
    {
    function MyWidgetName()
    {
    $widget_ops = array('classname' => 'MyWidgetName', 'description' => 'My Widget Description' );
    $this->WP_Widget('MyWidgetName', 'My Widget Title', $widget_ops);
    }

    function form($instance)
    {
    $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
    $title = $instance['title'];
    ?>
    <p><label for="<?php echo $this->get_field_id('title'); ?>">Title: <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></label></p>
    <?php
    }

    function update($new_instance, $old_instance)
    {
    $instance = $old_instance;
    $instance['title'] = $new_instance['title'];
    return $instance;
    }

    function widget($args, $instance)
    {
    extract($args, EXTR_SKIP);

    echo $before_widget;
    $title = empty($instance['title']) ? ' ' : apply_filters('widget_title', $instance['title']);

    if (!empty($title))
    echo '<h3 class="widget-title">' . $title . '</h3>';

    // WIDGET CODE GOES HERE

    }

    }
    add_action( 'widgets_init', create_function('', 'return register_widget("MyWidgetName");') );

    ?>