SHOW:
|
|
- or go back to the newest paste.
| 1 | <?php | |
| 2 | error_reporting(E_ALL); | |
| 3 | /* | |
| 4 | - | Plugin Name: Custom Widget |
| 4 | + | Plugin Name: Featured Resources |
| 5 | Plugin URI: http://wpguru.in | |
| 6 | - | Description: Custom Widget.. |
| 6 | + | Description: Featured resources widget for WPGuru.in |
| 7 | Author: Rakesh Raja | |
| 8 | - | Version: 1.6 |
| 8 | + | Version: 1.0 |
| 9 | Author URI: http://wpguru.in | |
| 10 | */ | |
| 11 | ||
| 12 | - | /*main widget class starts here*/ |
| 12 | + | class FeaturedResources extends WP_Widget |
| 13 | - | class wpg_textwidget extends WP_Widget {
|
| 13 | + | |
| 14 | - | |
| 14 | + | function FeaturedResources() |
| 15 | {
| |
| 16 | - | /*construct widget /display it */ |
| 16 | + | $widget_ops = array('classname' => 'fearesources', 'description' => 'Featured Resources' );
|
| 17 | - | function __construct() |
| 17 | + | $this->WP_Widget('FeaturedResources', 'Featured Resources', $widget_ops);
|
| 18 | - | {
|
| 18 | + | } |
| 19 | - | $params = array( |
| 19 | + | |
| 20 | - | 'description' => 'Simple Text Widget', |
| 20 | + | function form($instance) |
| 21 | - | 'name' => 'WPG Text Widget' |
| 21 | + | {
|
| 22 | - | ); |
| 22 | + | $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) ); |
| 23 | - | |
| 23 | + | $title = $instance['title']; |
| 24 | - | parent:: __construct('wpg_textwidget', '', $params);
|
| 24 | + | ?> |
| 25 | - | } /* construct of widget ends here */ |
| 25 | + | <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 attribute_escape($title); ?>" /></label></p>
|
| 26 | - | |
| 26 | + | |
| 27 | - | /*widget form starts here*/ |
| 27 | + | } |
| 28 | - | public function form($instance) |
| 28 | + | |
| 29 | - | {
|
| 29 | + | function update($new_instance, $old_instance) |
| 30 | - | extract($instance); |
| 30 | + | {
|
| 31 | - | |
| 31 | + | $instance = $old_instance; |
| 32 | - | ?> |
| 32 | + | $instance['title'] = $new_instance['title']; |
| 33 | return $instance; | |
| 34 | - | <p> |
| 34 | + | } |
| 35 | - | <label for="<?php echo $this->get_field_id( 'title' ); ?>"> Title: </label> |
| 35 | + | |
| 36 | - | <input type="text" class="widefat" |
| 36 | + | function widget($args, $instance) |
| 37 | - | id="<?php echo $this->get_field_id( 'title' ); ?>" |
| 37 | + | {
|
| 38 | - | name="<?php echo $this->get_field_name( 'title' ); ?>" |
| 38 | + | extract($args, EXTR_SKIP); |
| 39 | - | value="<?php if( isset($title) ) echo esc_attr($title); ?>" /> |
| 39 | + | |
| 40 | - | |
| 40 | + | echo $before_widget; |
| 41 | - | <label for="<?php echo $this->get_field_id( 'info' ); ?>"> Info: </label> |
| 41 | + | $title = empty($instance['title']) ? ' ' : apply_filters('widget_title', $instance['title']);
|
| 42 | - | <textarea class="widefat" |
| 42 | + | |
| 43 | - | id="<?php echo $this->get_field_id( 'info' ); ?>" |
| 43 | + | if (!empty($title)) |
| 44 | - | name="<?php echo $this->get_field_name( 'info' ); ?>" ><?php if( isset($info) ) echo esc_attr($info); ?> |
| 44 | + | echo $before_title . $title . $after_title;; |
| 45 | - | </textarea> |
| 45 | + | |
| 46 | - | |
| 46 | + | // WIDGET CODE GOES HERE ?> |
| 47 | ||
| 48 | - | } /* widget form ends here */ |
| 48 | + | <!--resource post--> |
| 49 | - | /* this print widget on theme page */ |
| 49 | + | <div class="sposts"> |
| 50 | - | public function widget($args, $instance) |
| 50 | + | |
| 51 | - | {
|
| 51 | + | $args = array( 'post_type' => 'resource'); |
| 52 | - | extract($args); |
| 52 | + | $loop = new WP_Query( $args ); |
| 53 | - | extract($instance); |
| 53 | + | while ( $loop->have_posts()) : $loop->the_post(); |
| 54 | - | |
| 54 | + | if (get_field('featured') == "yes" ) {
|
| 55 | - | echo $before_widget; |
| 55 | + | echo '<a href="'; |
| 56 | - | echo $before_title . $title . $after_title; |
| 56 | + | the_permalink(); |
| 57 | - | echo $info; |
| 57 | + | echo '"><div class="spost"><h2>'; |
| 58 | - | echo $after_widget; |
| 58 | + | the_title(); |
| 59 | - | |
| 59 | + | echo '</h2><div class="left"><img src="'; |
| 60 | - | }/* print widget ends here */ |
| 60 | + | the_field('thumb');
|
| 61 | echo'" alt=""></div><div class="right">'; | |
| 62 | echo content('100');
| |
| 63 | - | } /*end if main widget class*/ |
| 63 | + | echo'<span>Click here to go to read more... </span></div>'; |
| 64 | echo'<div style="clear:both;"></div></div></a>'; | |
| 65 | - | add_action('widgets_init', 'wpg_register_wpgtextwidget');
|
| 65 | + | |
| 66 | - | function wpg_register_wpgtextwidget() |
| 66 | + | endwhile; |
| 67 | ?> | |
| 68 | - | register_widget('wpg_textwidget');
|
| 68 | + | </div> |
| 69 | <!--resource post--> | |
| 70 | - | ?> |
| 70 | + | |
| 71 | <?php echo $after_widget; | |
| 72 | } | |
| 73 | ||
| 74 | } | |
| 75 | add_action( 'widgets_init', create_function('', 'return register_widget("FeaturedResources");') );?> |