wp/wp-content/themes/IN-MOTION-package-u1/in-motion/functions/widget-posts.php
changeset 0 d970ebf37754
child 16 a86126ab1dd4
equal deleted inserted replaced
-1:000000000000 0:d970ebf37754
       
     1 <?php
       
     2 
       
     3 /*
       
     4 
       
     5 	Plugin Name: Post Widget
       
     6 	Description: Plugin is used for posts.
       
     7 	Author:
       
     8 	Version: 1.0
       
     9 	Author URI: 
       
    10  
       
    11 */
       
    12 
       
    13 class post_widget extends WP_Widget {
       
    14 
       
    15 
       
    16 /*-----------------------------------------------------------------------------------*/
       
    17 /*	Widget Setup
       
    18 /*-----------------------------------------------------------------------------------*/
       
    19 	
       
    20 function post_Widget() {
       
    21 
       
    22 	$widget_options = array(
       
    23 		'classname' => 'post_widget',
       
    24 		'description' => 'Custom post widget.');
       
    25 
       
    26 	$control_options = array(    //dodama svoje incializirane mere
       
    27 		'width' => 200,
       
    28 		'height' => 400,
       
    29 		'id_base' => 'post_widget'
       
    30 	);
       
    31 
       
    32 	$this->WP_Widget( 'post_widget', 'Post Widget', $widget_options, $control_options );
       
    33 	
       
    34 }
       
    35 
       
    36 
       
    37 
       
    38 function widget( $args, $instance ) {
       
    39 	
       
    40 	extract( $args );
       
    41 	$title = apply_filters('widget_title', $instance['title'] );
       
    42 	$username = $instance['username'];
       
    43 	$posts_number = $instance['posts_number'];
       
    44 
       
    45 	echo $before_widget;
       
    46 	
       
    47 	if ( $title )
       
    48 	{
       
    49 		echo $before_title;
       
    50 		echo $title;
       
    51 		echo $after_title;
       
    52 	}
       
    53 	
       
    54 	$args = array('posts_per_page' => $posts_number, 'order'=> 'DESC', 'orderby' => 'post_date'  );
       
    55 
       
    56 	$port_query = new WP_Query( $args );
       
    57                 
       
    58    if( $port_query->have_posts() ) : while( $port_query->have_posts() ) : $port_query->the_post(); 
       
    59 				
       
    60 						?>
       
    61 						<div class="fl" style="width:200px;">
       
    62 							<div class="mypost_widget_img fl"> 
       
    63 								<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?>
       
    64 								<a href="<?php the_permalink();?>">						
       
    65 									 <img  src="<?php echo get_template_directory_uri(); ?>/functions/crop.php?h=100&w=100&f=<?php echo $image[0]; ?>" /> 
       
    66 								</a>
       
    67 							</div>
       
    68 							<div class="mypost_widget_text fl"> 
       
    69 							   <a  href="<?php the_permalink();?>"><?php echo get_the_title($post->ID); ?></a>
       
    70 							   <div class="date"><?php the_time('F j, Y'); ?></div>
       
    71 							</div>	
       
    72 						</div>
       
    73 										
       
    74 				
       
    75 	<?php endwhile; endif; wp_reset_postdata(); ?>
       
    76 	
       
    77 	<div class="clear"></div>		
       
    78 	<?php
       
    79      
       
    80  	
       
    81 	echo $after_widget;
       
    82 	
       
    83 }
       
    84 
       
    85 
       
    86 function form( $instance ) {  
       
    87 
       
    88 	/* Set the default values  */
       
    89 		$defaults = array(
       
    90 		'title' => 'Post Widget',
       
    91 		'posts_number' => '3',
       
    92 		);
       
    93 		$instance = wp_parse_args( (array) $instance, $defaults ); 
       
    94 
       
    95 	 ?>
       
    96 
       
    97 		<label for="<?php echo $this->get_field_id( 'title' ); ?>">
       
    98 		<?php _e('Title:','pego_tr'); ?>
       
    99 		<input class="widefat" type="text" id="<?php echo $this->get_field_id( 'title' ); ?>" 
       
   100 				 name="<?php echo $this->get_field_name( 'title' ); ?>" 
       
   101 				 value="<?php echo $instance['title']; ?>" />
       
   102 		</label>
       
   103 																													
       
   104 		<label for="<?php echo $this->get_field_id( 'posts_number' ); ?>">
       
   105 		<?php _e('Number of posts:','pego_tr'); ?>
       
   106 		<input class="widefat" type="text" id="<?php echo $this->get_field_id( 'posts_number' ); ?>" 
       
   107 				 name="<?php echo $this->get_field_name( 'posts_number' ); ?>" 
       
   108 				 value="<?php echo $instance['posts_number']; ?>" />
       
   109 		</label>
       
   110 
       
   111 			
       
   112 	<?php
       
   113 	}
       
   114 }
       
   115 
       
   116 
       
   117 /*     Adding widget to widgets_init and registering flickr widget    */
       
   118 add_action( 'widgets_init', 'post_widgets' );
       
   119 
       
   120 function post_widgets() {
       
   121 	register_widget( 'post_Widget' );
       
   122 }
       
   123 ?>