RtThemesSupport

rttheme9 news widget with image.

Nov 25th, 2013
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.03 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: RT-THEME NEWS WIDGET
  4. Plugin URI: http://themeforest.net/user/stmcan?ref=stmcan
  5. Description: This widget developed for RT- Wordpress Themes. Adds latest blog posts.
  6. Version: 1.0
  7. Author: Tolga can
  8. Author URI: http://themeforest.net/user/stmcan?ref=stmcan
  9. */
  10.  
  11. /* RT_THEME_NEWS_WIDGET Class */
  12. class RT_THEME_NEWS_WIDGET extends WP_Widget {
  13.     function RT_THEME_NEWS_WIDGET() {
  14.         $widget_ops = array( 'classname' => 'rt-theme-news-widget', 'description' => 'Adds a latest blog posts.' );
  15.         parent::WP_Widget( 'css-rt-theme-news-widget', 'RT-THEME NEWS WIDGET', $widget_ops );
  16.     }
  17.  
  18.  
  19.     function widget($args, $instance) {
  20.     global $more,$post,$which_home;
  21.         extract( $args );
  22.      
  23.     $title = apply_filters('title', $instance['title']);
  24.     $rt_news_id= apply_filters('rt_news_id', $instance['rt_news_id']);
  25.     $rt_news_number= apply_filters('rt_news_number', $instance['rt_news_number']);
  26.     $full_size= isset( $instance['full_size'] ) ? $instance['full_size']  : "";
  27.     $hide_date= isset( $instance['hide_date'] ) ? $instance['hide_date'] : "";
  28.  
  29.  
  30.     if (apply_filters('link_text', $instance['link_text'])!=''){
  31.         $link_text =apply_filters('link_text', $instance['link_text']);
  32.     }else{
  33.         $link_text =__('read more','rt_theme');    
  34.     }
  35.    
  36.     if ($id=="home-page-widget"){
  37.         $home_page=1;
  38.     }else{
  39.         $home_page="";
  40.     }
  41.  
  42.  
  43.     if($home_page && $full_size && $which_home==1){
  44.         $box_class = "single";
  45.     }elseif ($home_page && $full_size && $which_home==2) {
  46.         $box_class = "single fullbox";
  47.     }else{
  48.         $box_class = "small";
  49.     }  
  50.    
  51.     if(!$rt_news_number){
  52.         $rt_news_number="10";      
  53.     }  
  54.    
  55.  
  56.     ?>
  57.  
  58.  
  59.     <!-- news box -->
  60.  
  61.         <div class="box <?php echo $box_class;?>">
  62.  
  63.             <!-- box title-->
  64.             <?php if($home_page && $full_size):?>
  65.             <h3><?php echo $title;?></h3>
  66.             <?php else:?>
  67.             <h4><?php echo $title;?></h4>                      
  68.             <?php endif;?>
  69.  
  70.             <div class="textarea"><br />
  71.                 <!-- box title-->
  72.  
  73.  
  74.         <?php
  75.         $more = 0;
  76.         wp_reset_query();
  77.      
  78.         $args=array(
  79.            'post_type'=>'post',
  80.            'showposts'=>$rt_news_number,
  81.            'cat'=>$rt_news_id
  82.         );
  83.        
  84.        
  85.         $the_query = new WP_Query($args);
  86.         ?>
  87.  
  88.          
  89.  
  90.         <?php if ($the_query->have_posts()) : while ($the_query->have_posts()) : $the_query->the_post();
  91.  
  92.             $title=get_the_title();
  93.             $link=get_permalink();
  94.             $date=get_the_date();
  95.             $more = 0;         
  96.         ?>
  97.                 <!-- text-->
  98.                 <?php if(!$hide_date):?><span class="news_date"><?php echo $date;?></span><br /><?php endif;?>
  99.                 <?php echo $title; ?>
  100.                             <?php if(get_post_meta($post->ID, 'rt_post_image', true) && $home_page):?>
  101.                             <!-- blog image-->
  102.                                 <?php if(!get_option('rttheme_blog_resize')):
  103.                                     // Resize Image
  104.                                     if (get_option('rttheme_homepage_style')){
  105.                                     $which_home=get_option('rttheme_homepage_style');
  106.                                     }else{
  107.                                     $which_home="1";       
  108.                                     }  
  109.  
  110.                                     $imgURL = find_image_org_path(get_post_meta($post->ID, 'rt_post_image', true));
  111.                                     $crop   = true;
  112.                                     if ($full_size) {
  113.                                     if ($which_home=="1") {
  114.                                     if($imgURL) $image_thumb = @vt_resize( '', $imgURL, 615, 320, ''.$crop.'' );
  115.                                     }
  116.                                     else {
  117.                                     if($imgURL) $image_thumb = @vt_resize( '', $imgURL, 922, 480, ''.$crop.'' );
  118.                                     }
  119.                                     }
  120.                                     else{
  121.                                     if($imgURL) $image_thumb = @vt_resize( '', $imgURL, 295, 155, ''.$crop.'' );
  122.                                     }
  123.                                 ?>
  124.                                     <a href="<?php echo get_post_meta($post->ID, 'rt_post_image', true);?>" title="" rel="prettyPhoto[rt_theme_blog]" ><img src="<?php echo $image_thumb["url"];?>" alt=""  class="aligncenter post_image preload" /></a>
  125.                                 <?php else:?>
  126.                                     <img src="<?php echo get_post_meta($post->ID, 'rt_post_image', true);?>" alt="" class="aligncenter post_image preload" />
  127.                                 <?php endif;?>
  128.                             <!-- / blog image -->
  129.                             <?php endif;?>             
  130.                 <?php if ($home_page) {the_excerpt();} ?>              
  131.                 <a href="<?php echo $link;?>" class="read_more" title="<?php echo $title;?>"><?php echo $link_text;?></a>
  132.                 <br />
  133.                 <div class="news_line"></div>
  134.         <?php endwhile; endif;wp_reset_query();?>
  135.        
  136.         </div>
  137.         </div>
  138.     <!-- /news box -->
  139.        
  140.  
  141.        
  142.     <?php
  143.     }
  144.  
  145.     function update($new_instance, $old_instance) {            
  146.         return $new_instance;
  147.     }
  148.  
  149.     function form($instance) {
  150.     global $rt_getcat;
  151.  
  152.     $title = isset($instance['title']) ? esc_attr($instance['title']) : "";
  153.     $rt_news_number= isset($instance['rt_news_number']) ? esc_attr($instance['rt_news_number']) : "";
  154.     $rt_news_id = isset($instance['rt_news_id']) ? esc_attr($instance['rt_news_id']) : "";
  155.     $hide_date= isset($instance['hide_date']) ? esc_attr($instance['hide_date']) : "";
  156.     $link_text =  isset($instance['link_text']) ?  esc_attr($instance['link_text']): "";
  157.     $full_size= isset($instance['full_size']) ? esc_attr($instance['full_size']) : "";  
  158.  
  159.  
  160.     ?>
  161.     <div class="rt-theme-widget">
  162.  
  163.     <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:','rt_theme_admin'); ?> <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; ?>" /></label></p>
  164.  
  165.     Choose a category<br />
  166.     <p>
  167.         <select name="<?php echo $this->get_field_name('rt_news_id'); ?>">  id="<?php echo $this->get_field_id('rt_news_id'); ?>" >
  168.             <?php foreach ($rt_getcat as $op_val=>$option) { ?>
  169.         <option value="<?php echo $op_val;?>" <?php if ( $rt_news_id  == $op_val) { echo ' selected="selected" '; }?>><?php _e($option); ?></option>
  170.         <?php } ?>
  171.         </select>
  172.        
  173.         </label>
  174.     </p>
  175.  
  176.  
  177.     <p> <label for="<?php echo $this->get_field_id('hide_date'); ?>"><?php _e('Hide Dates:','rt_theme_admin'); ?></label> <input  id="<?php echo $this->get_field_id('hide_date'); ?>"   <?php if($hide_date=='on') echo "checked";?> name="<?php echo $this->get_field_name('hide_date'); ?>" type="checkbox"></p>
  178.  
  179.     <p><label for="<?php echo $this->get_field_id('rt_news_number'); ?>"><?php _e('Number Posts (default: \'10\'):','rt_theme_admin'); ?> <input class="widefat" id="<?php echo $this->get_field_id('rt_news_number'); ?>" name="<?php echo $this->get_field_name('rt_news_number'); ?>" type="text" value="<?php echo $rt_news_number; ?>" /></label></p>
  180.      
  181.     <p><label for="<?php echo $this->get_field_id('link_text'); ?>"><?php _e('Link text (default: \'read more\'):','rt_theme_admin'); ?> <input class="widefat" id="<?php echo $this->get_field_id('link_text'); ?>" name="<?php echo $this->get_field_name('link_text'); ?>" type="text" value="<?php echo $link_text; ?>" /></label></p>
  182.        
  183.      <hr />
  184.      <small>You can use this box in single line if you are using for home page!</small>
  185.      <p> <label for="<?php echo $this->get_field_id('full_size'); ?>"><?php _e('Full Width Box:','rt_theme_admin'); ?></label> <input  id="<?php echo $this->get_field_id('full_size'); ?>"   <?php if($full_size=='on') echo "checked";?> name="<?php echo $this->get_field_name('full_size'); ?>" type="checkbox"></p>
  186.      <hr />
  187.  
  188.     </div>
  189.  
  190. <?php // end class
  191. }
  192. }
  193. ?>
  194. <?php // register RT_THEME_NEWS_WIDGET widget
  195. add_action('widgets_init', create_function('', 'return register_widget("RT_THEME_NEWS_WIDGET");'));
  196. ?>
Advertisement
Add Comment
Please, Sign In to add comment