web/wp-content/plugins/posts-of-current-category/posts-of-current-category.php
changeset 194 32102edaa81b
parent 136 bde1974c263b
equal deleted inserted replaced
193:2f6f6f7551ca 194:32102edaa81b
     1 <?php
     1 <?php
     2 /*
     2 /*
     3 Plugin Name: Posts of Current Category
     3 Plugin Name: Posts of Current Category
     4 Plugin URI: http://anupraj.com.np/home/wp-plugins/display-posts-of-current-category-widget/
     4 Plugin URI: http://anupraj.com.np/index.php/display-posts-of-current-category-widget/68
     5 Description: Lists (Show/Display title) Posts of Current Category and Order Posts by author,content,date,ID, .. etc  Sort ASC/DESC. Go to Appearance>Widgets and Drag "Posts of Current Category" widget to your Sidebar.
     5 Description: Lists (Show/Display title) Posts of Current Category and Order Posts by author,content,date,ID, .. etc  Sort ASC/DESC. Go to Appearance>Widgets and Drag "Posts of Current Category" widget to your Sidebar.
     6 Version: 0.1
     6 Version: 0.4
     7 Author: Anup Raj
     7 Author: Anup Raj
     8 Author URI: http://anupraj.com.np/home/
     8 Author URI: http://anupraj.com.np/
     9 // modified by sam 21/01/2010
       
    10 */
     9 */
    11 
    10 
    12 class posts_cur_cat extends WP_Widget {
    11 class posts_cur_cat extends WP_Widget {
    13 	function posts_cur_cat() {
    12 	function posts_cur_cat() {
    14 		$widget_ops = array('description' => __('Display Posts of current category and order it.', 'posts-of-cur-cat') );
    13 		$widget_ops = array('description' => __('Display Posts of current category and order it.', 'posts-of-cur-cat') );
    16 		$this->WP_Widget('postsofcurrentcategory', __('Posts of Current Category', 'posts-of-cur-cat'), $widget_ops);
    15 		$this->WP_Widget('postsofcurrentcategory', __('Posts of Current Category', 'posts-of-cur-cat'), $widget_ops);
    17 	}
    16 	}
    18 
    17 
    19   function widget($args, $instance) {
    18   function widget($args, $instance) {
    20 	 		extract($args, EXTR_SKIP);
    19 	 		extract($args, EXTR_SKIP);
    21 			echo $before_widget;
       
    22 			
    20 			
    23 			$title = empty($instance['title']) ? __('', 'posts-of-cur-cat') : apply_filters('widget_title', $instance['title']);
    21 			$title = empty($instance['title']) ? __('', 'posts-of-cur-cat') : apply_filters('widget_title', $instance['title']);
    24 			$parameters = array(
    22 			$parameters = array(
    25 			  'title' => $title,
    23 			  'title' => $title,
    26 				'limit' => (int) $instance['show-num'],
    24 				'limit' => (int) $instance['show-num'],
    27 				'excerpt' => (int) $instance['excerpt-length'],
    25 				'excerpt' => (int) $instance['excerpt-length'],
    28 				'AscDesc' => esc_attr($instance['AscDesc']),
    26 				'AscDesc' => esc_attr($instance['AscDesc']),
    29 				'OrderBy' => esc_attr($instance['OrderBy'])
    27 				'OrderBy' => esc_attr($instance['OrderBy'])
    30 				
    28 				
    31 			);
    29 			);
       
    30 			echo $before_title;
       
    31 			echo '<a href="';
       
    32 			echo get_permalink($post->post_parent);
       
    33 			echo '" tile="';
    32 			if ( !empty( $title ) ) {
    34 			if ( !empty( $title ) ) {
    33 		    echo $before_title . $title . $after_title;
    35 				echo $title;
    34 			};
    36 				echo '">';
       
    37 				echo $title;
       
    38 			}else{
       
    39 				if($post->post_parent) {
       
    40 					$parent_title = get_the_title($post->post_parent);
       
    41 					echo $parent_title;
       
    42 					echo '">';
       
    43 					echo $parent_title;
       
    44 				} else {
       
    45 					wp_title('');
       
    46 					echo '">';
       
    47 					wp_title('');
       
    48 				}
       
    49 			}
       
    50 			echo '</a>';
       
    51 			echo $after_title;
    35 			
    52 			
    36 			//print recent posts
    53 			echo $before_widget;
    37 			post_of_curCat($parameters);
    54 			if (is_page()){
       
    55 			/*
       
    56 				if($post->post_parent){
       
    57 					$children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0&sort_column=menu_order"); 
       
    58 				}else{
       
    59 					$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0&sort_column=menu_order");
       
    60 				}
       
    61 				if ($children && !$s) { 
       
    62 					//echo '<ul>';
       
    63 					echo $children; 
       
    64 					//echo '</ul>';
       
    65 				}
       
    66 			*/
       
    67 			}
       
    68 			if(is_category()){//print recent posts
       
    69 					post_of_curCat($parameters);
       
    70 			}
    38 			echo $after_widget;
    71 			echo $after_widget;
    39 			
    72 			
    40   } //end of widget
    73   } //end of widget
    41 	
    74 	
    42 	//Update widget options
    75 	//Update widget options
    72 		$OrderBy = esc_attr($instance['OrderBy']);
   105 		$OrderBy = esc_attr($instance['OrderBy']);
    73 
   106 
    74 		?>
   107 		?>
    75 		<p>
   108 		<p>
    76 		   <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:');?> 
   109 		   <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:');?> 
    77 			<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; ?>" />
   110 			<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; ?>" /><br />
       
   111 			<em>Leave this field blank, if you want to display Parent's Post's or Page's Title on widget heading</em>
    78 		   </label>
   112 		   </label>
    79 		</p>
   113 		</p>
    80 		<p>
   114 		<p>
    81 		   <label for="<?php echo $this->get_field_id('show-num'); ?>"><?php _e('Number of posts to show:');?> 
   115 		   <label for="<?php echo $this->get_field_id('show-num'); ?>"><?php _e('Number of posts to show:');?> 
    82 		  <input id="<?php echo $this->get_field_id('show-num'); ?>" name="<?php echo $this->get_field_name('show-num'); ?>" type="text" value="<?php echo $show_num; ?>" size ="3" /><br />
   116 		  <input id="<?php echo $this->get_field_id('show-num'); ?>" name="<?php echo $this->get_field_name('show-num'); ?>" type="text" value="<?php echo $show_num; ?>" size ="3" /><br />
   146 	
   180 	
   147 	$query = "&category=$curCategoryID&showposts=$limit&orderby=$OrderBy&order=$AscDesc";
   181 	$query = "&category=$curCategoryID&showposts=$limit&orderby=$OrderBy&order=$AscDesc";
   148 	$posts = get_posts($query); //get posts
   182 	$posts = get_posts($query); //get posts
   149 	$postlist = '';	
   183 	$postlist = '';	
   150     foreach ($posts as $post) {
   184     foreach ($posts as $post) {
   151 		$post_title_s = htmlspecialchars(stripslashes(cache_cutter($post->post_title)));
   185 		$post_title = htmlspecialchars(stripslashes($post->post_title));
   152 		$post_title_l = htmlspecialchars(stripslashes(text_cutter($post->post_title,200)));
   186 		$postlist .= '<li><a href="' . get_permalink($post->ID) . '" title="'. $post_title .'" >' . $post_title . '</a> </li>';
   153 		// modif here (cache_cutter(); ) 				
       
   154 		$postlist .= '<li><a href="' . get_permalink($post->ID) . '" title="'.  $post_title_s .'" >' . $post_title_l . ' </a> </li>';
       
   155     }
   187     }
   156 	
   188 	
   157 	echo '<ul class="advanced-recent-posts">';		
   189 	echo '<ul class="posts-of-current-category">';		
   158 		echo $postlist;
   190 		echo $postlist;
   159 	echo '</ul>';
   191 	echo '</ul>';
   160  }
   192  }
   161 
       
   162 ?>
   193 ?>