Featured image on widget
-
Been experimenting and cant quite get this to work.
Has anybody modified the widgets .php file to have it display the featured image of each top rated post in the widget?
Thx
Viewing 1 replies (of 1 total)
-
i am not web developer, sorry for bad coding 🙂
View:
http://i.imgur.com/JWhieq2.jpgLive View:
http://www.zvtr.comCode:
http://www.codeshare.io/LlUVs<?php // Make sure class does not already exist (Playing safe) and that the get function exists if(!class_exists('BhittaniPlugin_kkStarRatings_Widget') && function_exists('kk_star_ratings_get')) : class BhittaniPlugin_kkStarRatings_Widget extends WP_Widget { // Runs when OBJECT DECLARED (Instanciated) public function BhittaniPlugin_kkStarRatings_Widget() { $widget_options = array( 'classname' => 'kk-star-ratings-widget', 'description' => 'Show top rated posts' ); parent::WP_Widget('BhittaniPlugin_kkStarRatings_Widget', 'kk Star Ratings', $widget_options); } // Outputs USER INTERFACE public function widget($args, $instance) { extract( $args, EXTR_SKIP ); $title = ( !empty($instance['title']) ) ? $instance['title'] : 'Top Posts'; $total = ( !empty($instance['noofposts']) ) ? $instance['noofposts'] : '5'; $category = ( $instance['category'] ) ? $instance['category'] : false; $sr = ($instance['showrating']) ? true : false; echo $before_widget; echo $before_title . $title . $after_title; // OUTPUT starts $posts = kk_star_ratings_get($total, $category); echo '<table><tbody>'; foreach ($posts as $post) { echo "<tr><td><a href='".get_permalink($post->ID)."'>".get_the_post_thumbnail($post->ID , 'thumbnail')."</a></td><td style='vertical-align:bottom'><a href='".get_permalink($post->ID)."'>".$post->post_title."</a>"; if($sr) { echo " <span style='font-size:10px;'>(".$post->ratings."/5)</span></td>"; } echo "</tr>"; } echo '</tbody></table>'; // OUTPUT ends echo $after_widget; } // Updates OPTIONS /* public function update() { } */ // The option FORM public function form( $instance ) { ?> <p> <label for="<?php echo $this->get_field_id('title'); ?>">Title: <input id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr(!empty($instance['title'])?$instance['title']: 'Top Posts'); ?>" /></label> </p> <p> <label for="<?php echo $this->get_field_id('noofposts'); ?>">No of Posts: <input id="<?php echo $this->get_field_id('noofposts'); ?>" name="<?php echo $this->get_field_name('noofposts'); ?>" type="text" value="<?php echo esc_attr(!empty($instance['noofposts'])?$instance['noofposts']: '5'); ?>" size="3" /></label> </p> <p> <label for="<?php echo $this->get_field_id('showrating'); ?>">Show Average?: <select id="<?php echo $this->get_field_id('showrating'); ?>" name="<?php echo $this->get_field_name('showrating'); ?>"> <option value="0" <?php if(isset($instance['showrating']) && !esc_attr($instance['showrating'])){echo "selected='selected'";} ?>>No</option> <option value="1" <?php if(isset($instance['showrating']) && esc_attr($instance['showrating'])){echo "selected='selected'";} ?>>Yes</option> </select> </label> </p> <p> <label for="<?php echo $this->get_field_id('category'); ?>">Filter by Category: <select id="<?php echo $this->get_field_id('category'); ?>" name="<?php echo $this->get_field_name('category'); ?>"> <option value="0">Select</option> <?php foreach(get_categories(array()) as $category) { echo '<option value="'.$category->term_id.'"'; if(isset($instance['category']) && esc_attr($instance['category'])==$category->term_id) echo ' selected="selected"'; echo '>'.$category->name.'</option>'; } ?> </select> </label> </p> <?php } } if(!function_exists('kk_star_ratings_widget_init')) { function kk_star_ratings_widget_init() { register_widget('BhittaniPlugin_kkStarRatings_Widget'); } add_action('widgets_init', 'kk_star_ratings_widget_init'); } endif; ?>
Viewing 1 replies (of 1 total)
The topic ‘Featured image on widget’ is closed to new replies.