Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: RT-THEME NEWS WIDGET
- Plugin URI: http://themeforest.net/user/stmcan?ref=stmcan
- Description: This widget developed for RT- Wordpress Themes. Adds latest blog posts.
- Version: 1.0
- Author: Tolga can
- Author URI: http://themeforest.net/user/stmcan?ref=stmcan
- */
- /* RT_THEME_NEWS_WIDGET Class */
- class RT_THEME_NEWS_WIDGET extends WP_Widget {
- function RT_THEME_NEWS_WIDGET() {
- $widget_ops = array( 'classname' => 'rt-theme-news-widget', 'description' => 'Adds a latest blog posts.' );
- parent::WP_Widget( 'css-rt-theme-news-widget', 'RT-THEME NEWS WIDGET', $widget_ops );
- }
- function widget($args, $instance) {
- global $more,$post,$which_home;
- extract( $args );
- $title = apply_filters('title', $instance['title']);
- $rt_news_id= apply_filters('rt_news_id', $instance['rt_news_id']);
- $rt_news_number= apply_filters('rt_news_number', $instance['rt_news_number']);
- $full_size= isset( $instance['full_size'] ) ? $instance['full_size'] : "";
- $hide_date= isset( $instance['hide_date'] ) ? $instance['hide_date'] : "";
- if (apply_filters('link_text', $instance['link_text'])!=''){
- $link_text =apply_filters('link_text', $instance['link_text']);
- }else{
- $link_text =__('read more','rt_theme');
- }
- if ($id=="home-page-widget"){
- $home_page=1;
- }else{
- $home_page="";
- }
- if($home_page && $full_size && $which_home==1){
- $box_class = "single";
- }elseif ($home_page && $full_size && $which_home==2) {
- $box_class = "single fullbox";
- }else{
- $box_class = "small";
- }
- if(!$rt_news_number){
- $rt_news_number="10";
- }
- ?>
- <!-- news box -->
- <div class="box <?php echo $box_class;?>">
- <!-- box title-->
- <?php if($home_page && $full_size):?>
- <h3><?php echo $title;?></h3>
- <?php else:?>
- <h4><?php echo $title;?></h4>
- <?php endif;?>
- <div class="textarea"><br />
- <!-- box title-->
- <?php
- $more = 0;
- wp_reset_query();
- $args=array(
- 'post_type'=>'post',
- 'showposts'=>$rt_news_number,
- 'cat'=>$rt_news_id
- );
- $the_query = new WP_Query($args);
- ?>
- <?php if ($the_query->have_posts()) : while ($the_query->have_posts()) : $the_query->the_post();
- $title=get_the_title();
- $link=get_permalink();
- $date=get_the_date();
- $more = 0;
- ?>
- <!-- text-->
- <?php if(!$hide_date):?><span class="news_date"><?php echo $date;?></span><br /><?php endif;?>
- <?php echo $title; ?>
- <?php if(get_post_meta($post->ID, 'rt_post_image', true) && $home_page):?>
- <!-- blog image-->
- <?php if(!get_option('rttheme_blog_resize')):
- // Resize Image
- if (get_option('rttheme_homepage_style')){
- $which_home=get_option('rttheme_homepage_style');
- }else{
- $which_home="1";
- }
- $imgURL = find_image_org_path(get_post_meta($post->ID, 'rt_post_image', true));
- $crop = true;
- if ($full_size) {
- if ($which_home=="1") {
- if($imgURL) $image_thumb = @vt_resize( '', $imgURL, 615, 320, ''.$crop.'' );
- }
- else {
- if($imgURL) $image_thumb = @vt_resize( '', $imgURL, 922, 480, ''.$crop.'' );
- }
- }
- else{
- if($imgURL) $image_thumb = @vt_resize( '', $imgURL, 295, 155, ''.$crop.'' );
- }
- ?>
- <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>
- <?php else:?>
- <img src="<?php echo get_post_meta($post->ID, 'rt_post_image', true);?>" alt="" class="aligncenter post_image preload" />
- <?php endif;?>
- <!-- / blog image -->
- <?php endif;?>
- <?php if ($home_page) {the_excerpt();} ?>
- <a href="<?php echo $link;?>" class="read_more" title="<?php echo $title;?>"><?php echo $link_text;?></a>
- <br />
- <div class="news_line"></div>
- <?php endwhile; endif;wp_reset_query();?>
- </div>
- </div>
- <!-- /news box -->
- <?php
- }
- function update($new_instance, $old_instance) {
- return $new_instance;
- }
- function form($instance) {
- global $rt_getcat;
- $title = isset($instance['title']) ? esc_attr($instance['title']) : "";
- $rt_news_number= isset($instance['rt_news_number']) ? esc_attr($instance['rt_news_number']) : "";
- $rt_news_id = isset($instance['rt_news_id']) ? esc_attr($instance['rt_news_id']) : "";
- $hide_date= isset($instance['hide_date']) ? esc_attr($instance['hide_date']) : "";
- $link_text = isset($instance['link_text']) ? esc_attr($instance['link_text']): "";
- $full_size= isset($instance['full_size']) ? esc_attr($instance['full_size']) : "";
- ?>
- <div class="rt-theme-widget">
- <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>
- Choose a category<br />
- <p>
- <select name="<?php echo $this->get_field_name('rt_news_id'); ?>"> id="<?php echo $this->get_field_id('rt_news_id'); ?>" >
- <?php foreach ($rt_getcat as $op_val=>$option) { ?>
- <option value="<?php echo $op_val;?>" <?php if ( $rt_news_id == $op_val) { echo ' selected="selected" '; }?>><?php _e($option); ?></option>
- <?php } ?>
- </select>
- </label>
- </p>
- <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>
- <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>
- <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>
- <hr />
- <small>You can use this box in single line if you are using for home page!</small>
- <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>
- <hr />
- </div>
- <?php // end class
- }
- }
- ?>
- <?php // register RT_THEME_NEWS_WIDGET widget
- add_action('widgets_init', create_function('', 'return register_widget("RT_THEME_NEWS_WIDGET");'));
- ?>
Advertisement
Add Comment
Please, Sign In to add comment