Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class LatestProductsWidget extends WP_Widget
- {
- function LatestProductsWidget()
- {
- $widget_ops = array('classname' => 'LatestProductsWidget', 'description' => 'Displays the latest product additions with thumbnail' );
- $this->WP_Widget('LatestProductsWidget', 'Latest Products and Thumbnail', $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 attribute_escape($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 $before_title . $title . $after_title;;
- // WIDGET CODE GOES HERE
- query_posts('post_type=products&posts_per_page=3&order=DESC&meta_key=Rating&orderby=meta_value');
- if (have_posts()) :
- while (have_posts()) : the_post();
- echo "<a href='".get_permalink()."'>";
- the_title('<h2>','</h2>');
- the_post_thumbnail('thumbnail');
- the_meta();
- echo "</a>";
- endwhile;
- endif;
- wp_reset_query();
- echo $after_widget;
- }
- }
- add_action( 'widgets_init', create_function('', 'return register_widget("LatestProductsWidget");') );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement