RtThemesSupport

rt9-newswidget-withexcerpt

Mar 14th, 2013
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.48 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.  
  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= apply_filters('full_size', $instance['full_size']);
  27.    
  28.     $hide_date= apply_filters('hide_date', $instance['hide_date']);
  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"){$home_page=1;}
  37.  
  38.     if ($full_size && $home_page ) {
  39.     $sub_page_class="single";
  40.     }
  41.     else {$sub_page_class="small";}
  42.    
  43.     $box_image_width="220";    
  44.    
  45.     if(!$rt_news_number){
  46.         $rt_news_number="10";      
  47.     }  
  48.     ?>
  49.  
  50.  
  51.     <!-- news box -->
  52.  
  53.         <div class="box <?php if($home_page && $full_size && $which_home==1):?>single<?php elseif($home_page && $full_size && $which_home==2):?>single fullbox<?php else:?><?php echo $sub_page_class;?><?php endif;?>">
  54.  
  55.             <!-- box title-->
  56.             <?php if($home_page && $full_size):?>
  57.             <h3><?php echo $title;?></h3>
  58.             <?php else:?>
  59.             <h4><?php echo $title;?></h4>                      
  60.             <?php endif;?>
  61.  
  62.             <div class="textarea"><br />
  63.                 <!-- box title-->
  64.  
  65.  
  66.         <?php
  67.         $more = 0;
  68.         wp_reset_query();
  69.      
  70.         $args=array(
  71.            'post_type'=>'post',
  72.            'showposts'=>$rt_news_number,
  73.            'cat'=>$rt_news_id
  74.         );
  75.        
  76.        
  77.         $the_query = new WP_Query($args);
  78.         ?>
  79.  
  80.          
  81.  
  82.         <?php if ($the_query->have_posts()) : while ($the_query->have_posts()) : $the_query->the_post();
  83.  
  84.             $title=get_the_title();
  85.             $link=get_permalink();
  86.             $date=get_the_date();
  87.             $more = 0;         
  88.         ?>
  89.                 <!-- text-->
  90.                 <?php if(!$hide_date):?><span class="news_date"><?php echo $date;?></span><br /><?php endif;?>
  91.                 <?php echo $title; ?>
  92.                 <?php if ($home_page) {the_excerpt();} ?>
  93.                 <a href="<?php echo $link;?>" class="read_more" title="" <?php echo $open_page;?>><?php echo $link_text;?></a>
  94.                 <br />
  95.                 <div class="news_line"></div>
  96.         <?php endwhile; endif;wp_reset_query();?>
  97.        
  98.         </div>
  99.         </div>
  100.     <!-- /news box -->
  101.        
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.        
  109.     <?php
  110.     }
  111.  
  112.     function update($new_instance, $old_instance) {            
  113.         return $new_instance;
  114.     }
  115.  
  116.     function form($instance) {
  117.     global $rt_getcat;
  118.     $title = esc_attr($instance['title']);
  119.     $rt_news_number= esc_attr($instance['rt_news_number']);
  120.     $rt_news_id = esc_attr($instance['rt_news_id']);
  121.     $full_size= esc_attr($instance['full_size']);
  122.     $hide_date= esc_attr($instance['hide_date']);
  123.     $link_text = esc_attr($instance['link_text']); 
  124.     ?>
  125.     <div class="rt-theme-widget">
  126.  
  127.     <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('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 $title; ?>" /></label></p>
  128.  
  129.     Choose a category<br />
  130.     <p>
  131.         <select name="<?php echo $this->get_field_name('rt_news_id'); ?>">  id="<?php echo $this->get_field_id('rt_news_id'); ?>" >
  132.             <?php foreach ($rt_getcat as $op_val=>$option) { ?>
  133.         <option value="<?php echo $op_val;?>" <?php if ( $rt_news_id  == $op_val) { echo ' selected="selected" '; }?>><?php _e($option); ?></option>
  134.         <?php } ?>
  135.         </select>
  136.        
  137.         </label>
  138.     </p>
  139.  
  140.  
  141.     <p> <label for="<?php echo $this->get_field_id('hide_date'); ?>"><?php _e('Hide Dates:'); ?></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>
  142.  
  143.     <p><label for="<?php echo $this->get_field_id('rt_news_number'); ?>"><?php _e('Number Posts (default: \'10\'):'); ?> <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>
  144.      
  145.     <p><label for="<?php echo $this->get_field_id('link_text'); ?>"><?php _e('Link text (default: \'read more\'):'); ?> <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>
  146.        
  147.      <hr />
  148.      <small>You can use this box in single line if you are using for home page!</small>
  149.      <p> <label for="<?php echo $this->get_field_id('full_size'); ?>"><?php _e('Full Width Box:'); ?></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>
  150.      <hr />
  151.  
  152.     </div>
  153.  
  154. <?php // end class
  155. }
  156. }
  157. ?>
  158. <?php // register RT_THEME_NEWS_WIDGET widget
  159. add_action('widgets_init', create_function('', 'return register_widget("RT_THEME_NEWS_WIDGET");'));
  160. ?>
Advertisement
Add Comment
Please, Sign In to add comment