RtThemesSupport

rttheme18 latest_post.php

May 5th, 2014
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 8.34 KB | None | 0 0
  1. <?php
  2. #
  3. # RT-Theme Latest Posts With Thumbnails
  4. #
  5.  
  6. class Latest_Posts extends WP_Widget {
  7.  
  8.     function Latest_Posts() {
  9.         $opts =array(
  10.                     'classname'     => 'widget_latest_posts',
  11.                     'description'   => __( 'The most recent posts on your site with post thumbnails.', 'rt_theme_admin' )
  12.                 );
  13.  
  14.         $this-> WP_Widget('latest_posts', '['. RT_THEMENAME.']   '.__('Recent Posts ', 'rt_theme_admin'), $opts);
  15.     }
  16.    
  17.  
  18.     function widget( $args, $instance ) {
  19.  
  20.         $comment = "";
  21.        
  22.         extract( $args );
  23.         $title           = apply_filters('widget_title', $instance['title']) ;       
  24.         $categories      = empty($instance['categories']) ? $instance['categories'] : implode($instance['categories'],',') ;
  25.         $count           = empty($instance['count']) ? 5 : $instance['count'];
  26.         $limit           = empty($instance['limit']) ? 100 : $instance['limit'];
  27.         $show_thumbnails = $instance['show_thumbnails'];
  28.         $show_excerpt    = $instance['show_excerpt'];
  29.         $thumb_width     = empty($instance['thumb_width']) ? 50 : $instance['thumb_width'];
  30.         $thumb_height    = empty($instance['thumb_height']) ? 50 : $instance['thumb_height'];
  31.        
  32.        
  33.         //remove aside and quote post formats from the list
  34.         $postargs           = array('tax_query' => array( array( 'operator' => 'NOT IN', 'taxonomy' => 'post_format', 'field' => 'slug', 'terms' => array( 'post-format-quote' , 'post-format-aside' ) ) ),'post_type'=>'post','showposts'=>$count,'cat'=>$categories, 'nopaging' => 0, 'post_status' => 'publish', 'ignore_sticky_posts' => 1 ) ;
  35.                            
  36.         $post_query         =   new WP_Query($postargs);
  37.        
  38.  
  39.  
  40.         $rt_posts = '<div class="recent_posts clearfix"><ul>';
  41.    
  42.        
  43.         if ($post_query->have_posts()) : while ($post_query->have_posts()) : $post_query->the_post();                          
  44.            
  45.             $post_title    = get_the_title();
  46.             $link          = get_permalink();
  47.             $date          = get_the_time('d M Y');
  48.             $comment_count = get_comment_count( $post_query->post->ID );
  49.             $featured_image_id = get_post_thumbnail_id();
  50.  
  51.             // Create thumbnail image
  52.             $thumbnail_image_output = ! empty( $featured_image_id ) ? get_resized_image_output( array( "image_url" => "", "image_id" => $featured_image_id, "w" => $thumb_width, "h" => $thumb_height, "crop" => 1, "class"=>"recent-posts-thumb" ) ) : "";
  53.  
  54.  
  55.             $rt_posts .='<li class="clearfix">';
  56.  
  57.             if ( $thumbnail_image_output && ! $show_thumbnails ) :
  58.                 $rt_posts .= $thumbnail_image_output;
  59.             endif;     
  60.  
  61.  
  62.             if($comment_count['approved']>0) {
  63.  
  64.                 if($comment_count['approved'] > 1){
  65.                     $comments = $comment_count['approved'].' '. __('Comments','rt_theme');
  66.                 }
  67.                 else{
  68.                     $comments = __('1 Comment','rt_theme');
  69.                 }                              
  70.                 $comment =' <span class="comment_number"><span class="icon-comment-empty"></span><a href="'. get_comments_link() .'" title="'.$comments.'" class="comment_link">'. $comment_count['approved'].'</a></span>';
  71.             }  
  72.  
  73.             $rt_posts .='<span class="title"><a href="'.$link.'">'.$post_title.'</a></span>';          
  74.             $rt_posts .='<div class="widget-meta"><span class="date">'.$date.'</span> '.$comment.'</div>';
  75.             $rt_posts .= ($show_excerpt) ? ''.wp_html_excerpt(get_the_excerpt(),$limit).'... '.' <a class="more-link" href="'.$link.'">Continue reading</a>'.'<div class="space margin-b10"></div>' : "" ; 
  76.             $rt_posts .='</li>';
  77.  
  78.         endwhile;
  79.  
  80.         endif;
  81.         wp_reset_query();
  82.  
  83.         $rt_posts .= '</ul></div>';
  84.  
  85.         echo $before_widget;
  86.         if ($title) echo $before_title . $title . $after_title;
  87.         echo $rt_posts;
  88.         echo $after_widget;
  89.     }
  90.  
  91.     function update( $new_instance, $old_instance ) {
  92.          
  93.         $instance                     = $old_instance;
  94.         $instance['title']            = strip_tags($new_instance['title']);
  95.         $instance['categories']       = $new_instance['categories'];
  96.         $instance['newWidget']        = $new_instance['newWidget'];
  97.         $instance['limit']            = (int) $new_instance['limit'];
  98.         $instance['count']            = (int) $new_instance['count'];
  99.         $instance['show_thumbnails']  = !empty($new_instance['show_thumbnails']) ? 1 : 0;
  100.         $instance['show_excerpt']     = !empty($new_instance['show_excerpt']) ? 1 : 0;
  101.         $instance['thumb_width']      = !empty($new_instance['thumb_width']) ? intval($new_instance['thumb_width']) : 50;
  102.         $instance['thumb_height']     = !empty($new_instance['thumb_height']) ? intval($new_instance['thumb_height']) : 50;
  103.  
  104.         return $instance;
  105.     }
  106.  
  107.     function form( $instance ) {
  108.         $title           = isset($instance['title']) ? esc_attr($instance['title']) : '';
  109.         $categories      = isset($instance['categories']) ? $instance['categories'] : array();
  110.         $newWidget       = isset($instance['newWidget']) ? $instance['newWidget']: '';
  111.         $limit           = empty($instance['limit']) ? 100 : $instance['limit'];
  112.         $count           = empty($instance['count']) ? 5 : $instance['count'];
  113.         $show_thumbnails = isset($instance['show_thumbnails']) ? $instance['show_thumbnails']: '';
  114.         $show_excerpt    = isset($instance['show_excerpt']) ? $instance['show_excerpt']: '';
  115.         $thumb_width     = empty($instance['thumb_width']) ? 50 : $instance['thumb_width'];
  116.         $thumb_height    = empty($instance['thumb_height']) ? 50 : $instance['thumb_height'];      
  117.        
  118.         // Categories
  119.         $rt_getcat = RTTheme::rt_get_categories();
  120.        
  121.  
  122. ?>
  123.         <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:', 'rt_theme_admin'); ?></label>
  124.         <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title ?>" /></p>
  125.        
  126.        
  127.         <p><label for="<?php echo $this->get_field_id('categories'); ?>"><?php _e('Select Categories:', 'rt_theme_admin'); ?></label>
  128.        
  129.         <select class="widefat <?php echo empty($newWidget)? '' : 'multiple'; ?>"   name="<?php echo $this->get_field_name('categories'); ?>[]" id="<?php echo $this->get_field_id('categories'); ?>" multiple="multiple" title="<?php _e('Select','rt_theme_admin'); ?>">
  130.  
  131.             <?php
  132.             foreach ($rt_getcat as $op_val=>$option) {
  133.                 if($categories){
  134.                     foreach($categories as $a_key => $a_value){
  135.                         if ( $a_value ==  $op_val ){
  136.                             $selected   = "selected";
  137.                         }              
  138.                     }
  139.                 }
  140.              ?>
  141.                 <option value="<?php echo $op_val;?>" <?php echo empty($selected) ? "" :  'selected="selected"'; ?> >
  142.                     <?php  echo $option; ?>
  143.                 </option>
  144.             <?php
  145.             $selected='';
  146.             }
  147.             ?>
  148.         </select>
  149.  
  150.         <p><label for="<?php echo $this->get_field_id('count'); ?>"><?php _e('Number of posts to show:', 'rt_theme_admin'); ?></label>
  151.         <input id="<?php echo $this->get_field_id('count'); ?>" name="<?php echo $this->get_field_name('count'); ?>" type="text" value="<?php echo $count; ?>" size="4" /></p>
  152.  
  153.         <p><input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('show_excerpt'); ?>" name="<?php echo $this->get_field_name('show_excerpt'); ?>" <?php checked( $show_excerpt ); ?> />
  154.         <label for="<?php echo $this->get_field_id('show_excerpt'); ?>"><?php _e( 'Display Excerpt', 'rt_theme_admin' ); ?></label></p>
  155.  
  156.         <p><label for="<?php echo $this->get_field_id('limit'); ?>"><?php _e('Limit excerpt characters: ', 'rt_theme_admin'); ?></label>
  157.         <input id="<?php echo $this->get_field_id('limit'); ?>" name="<?php echo $this->get_field_name('limit'); ?>" type="text" value="<?php echo $limit; ?>" size="4" /></p>         
  158.  
  159.         <p><input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('show_thumbnails'); ?>" name="<?php echo $this->get_field_name('show_thumbnails'); ?>" <?php checked( $show_thumbnails ); ?> />
  160.         <label for="<?php echo $this->get_field_id('show_thumbnails'); ?>"><?php _e( 'Don\'t display post thumbnails', 'rt_theme_admin' ); ?></label></p>
  161.    
  162.         <p><label for="<?php echo $this->get_field_id('thumb_width'); ?>"><?php _e('Thumbnail Width (px):', 'rt_theme_admin'); ?></label>
  163.         <input id="<?php echo $this->get_field_id('thumb_width'); ?>" name="<?php echo $this->get_field_name('thumb_width'); ?>" type="text" value="<?php echo $thumb_width; ?>" size="4" /></p>
  164.    
  165.         <p><label for="<?php echo $this->get_field_id('thumb_height'); ?>"><?php _e('Thumbnail Height (px):', 'rt_theme_admin'); ?></label>
  166.         <input id="<?php echo $this->get_field_id('thumb_height'); ?>" name="<?php echo $this->get_field_name('thumb_height'); ?>" type="text" value="<?php echo $thumb_height; ?>" size="4" /></p>
  167.                
  168.         <input class="widefat" id="<?php echo $this->get_field_id('newWidget'); ?>" name="<?php echo $this->get_field_name('newWidget'); ?>" type="hidden" value="1" />
  169.        
  170. <?php } } ?>
Advertisement
Add Comment
Please, Sign In to add comment