RtThemesSupport

rttheme18 latest_post_2.php

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