web/wp-content/themes/selecta/ocmx/widgets/four-block-widget.php
changeset 1 0d28b7c10758
equal deleted inserted replaced
0:0d9a58d2c515 1:0d28b7c10758
       
     1 <?php
       
     2 class four_block_widget extends WP_Widget {
       
     3     /** constructor */
       
     4     function four_block_widget() {
       
     5         parent::WP_Widget(false, $name = "OCMX Thumbnail Widget", array("description" => "Four block thumbnail widget for the Home Page. Place in the 'Index Header Panel'."));	
       
     6     }
       
     7 
       
     8     /** @see WP_Widget::widget */
       
     9     function widget($args, $instance) {		
       
    10         extract( $args );
       
    11 		$widget_title =  esc_attr($instance["widget_title"]);
       
    12 		
       
    13 		if(!($instance["post_category"])) :
       
    14 			$use_catId = 0;
       
    15             $cat_query = "";
       
    16 		else :
       
    17 	        $use_category = $instance["post_category"];
       
    18 			$use_catId = get_category_by_slug($use_category);
       
    19             $cat_query = "&category_name=".$use_catId->cat_name;
       
    20 		endif;
       
    21        //Fetch the category for the widget
       
    22 		if(!($instance["post_offset"])) :
       
    23 	        $use_offset = 0;
       
    24 		else :
       
    25     	    $use_offset = $instance["post_offset"];
       
    26 		endif;
       
    27 		
       
    28        //Fetch the count for the widget
       
    29 		if(!($instance["post_count"])) :
       
    30 	        $post_count = 4;
       
    31 		else :
       
    32     	    $post_count = $instance["post_count"];
       
    33 		endif;
       
    34 		
       
    35 		$ocmx_featured = new WP_Query("showposts=$post_count&post_type=post".$cat_query);
       
    36 
       
    37 		//Set the post Aguments and Query accordingly
       
    38 		$count = 0;
       
    39 ?>
       
    40 		<div class="post-slider clearfix">
       
    41             <h2><?php echo $widget_title; ?></h2>
       
    42             <ul>
       
    43 				<?php while ($ocmx_featured->have_posts()) : $ocmx_featured->the_post();
       
    44 						setup_postdata($post);
       
    45 						$count++;
       
    46 						if ($count == 5) : 
       
    47 						$count = 1; ?>
       
    48 							</ul>
       
    49                             	</div>
       
    50                                 <div class="post-slider clearfix">
       
    51 							<ul>
       
    52 				<?php endif;
       
    53 						// Fetch the PermaLink, Thumbnail and Video Metas
       
    54 						$this_post = get_post($ocmx_featured->ID);
       
    55 						$get_post_video = get_post_meta($this_post->ID, "main_video", true);
       
    56 						$get_thumbnail = get_post_meta($this_post->ID, "other_media", true);
       
    57 						$get_video_thumbnail = get_post_meta($this_post->ID, "video_thumbnail", true);
       
    58 						$link = get_permalink($this_post->ID);
       
    59 						// Set our category
       
    60 						$category = get_the_category(); 			
       
    61 						// If we haven't used our custom image input, search for the first image in the post
       
    62 						$post_image = "";
       
    63 						if($get_thumbnail == "" && (get_option("ocmx_auto_home_images") && get_option("ocmx_auto_home_images") !== "no")) :
       
    64 							$post_image =  fetch_post_image($ocmx_featured->ID, "300", "600");
       
    65 						endif;
       
    66 				?>
       
    67                     <li<?php if($count == 4) : echo " class=\"last\""; endif;?>>
       
    68                         <div class="container-header-light-normal"><span></span></div>
       
    69                         <div class="container-light">
       
    70 							<div class="thumbnail">
       
    71 								<?php if ($get_video_thumbnail !== "") : 
       
    72 									/* Display Custom Video Image */
       
    73 								?>
       
    74 									<img src="<?php bloginfo('template_directory'); ?>/functions/timthumb.php?src=<?php echo $get_video_thumbnail ?>&amp;h=&amp;w=300&amp;zc=1" alt="<?php the_title(); ?>" />
       
    75 								<?php elseif ($post_image !== "") :
       
    76 									/* Display Post Image */
       
    77 									echo $post_image;
       
    78 								elseif ($get_thumbnail !== "") : 
       
    79 									/* Display Custom Post Image */
       
    80 								?>
       
    81 									<img src="<?php bloginfo('template_directory'); ?>/functions/timthumb.php?src=<?php echo $get_thumbnail ?>&amp;h=&amp;w=300&amp;zc=1" alt="<?php the_title(); ?>" />
       
    82 								<?php endif; ?>
       
    83 							</div>
       
    84                         </div>
       
    85                         <div class="container-footer-light-normal"><span></span></div>
       
    86                         <h3><a href="<?php echo $link; ?>"><?php echo $this_post->post_title; ?></a></h3>
       
    87                     </li>
       
    88                 <?php endwhile; ?>
       
    89             </ul>
       
    90         </div>
       
    91 <?php
       
    92     }
       
    93 
       
    94     /** @see WP_Widget::update */
       
    95     function update($new_instance, $old_instance) {
       
    96         return $new_instance;
       
    97     }
       
    98 
       
    99     /** @see WP_Widget::form */
       
   100     function form($instance) {
       
   101         $widget_title = 	esc_attr($instance["widget_title"]);
       
   102         $post_category = 	esc_attr($instance["post_category"]);
       
   103         $post_count = 		esc_attr($instance["post_count"]);
       
   104 		$post_offset =  	esc_attr($instance["post_offset"]);
       
   105 		
       
   106         ?>
       
   107         	<p>
       
   108             	<label for="<?php echo $this->get_field_id('widget_title'); ?>">Title
       
   109                 <input type="text" class="widefat" id="<?php echo $this->get_field_id('widget_title'); ?>" name="<?php echo $this->get_field_name('widget_title'); ?>" value="<?php echo $widget_title; ?>">
       
   110 			</p>
       
   111             <p>
       
   112             	<label for="<?php echo $this->get_field_id('post_count'); ?>">Post Count
       
   113                 <select size="1" class="widefat" id="<?php echo $this->get_field_id('post_count'); ?>" name="<?php echo $this->get_field_name('post_count'); ?>">
       
   114                 	<?php for($i = 4; $i < 25; $i=$i+4) : ?>
       
   115 	                    <option <?php if($post_count == $i) : ?>selected="selected"<?php endif; ?> value="<?php echo $i; ?>"><?php echo $i; ?></option>
       
   116                     <?php endfor; ?>
       
   117                 </select>
       
   118 			</p>
       
   119             <p>
       
   120             	<label for="<?php echo $this->get_field_id('post_offset'); ?>">Post Offset
       
   121                 <select size="1" class="widefat" id="<?php echo $this->get_field_id('post_offset'); ?>" name="<?php echo $this->get_field_name('post_offset'); ?>">
       
   122 	                    <option <?php if($post_offset == 0) : ?>selected="selected"<?php endif; ?> value="0">Latest Post</option>
       
   123                 	<?php for($i = 1; $i <= 8; $i++) : ?>
       
   124 	                    <option <?php if($post_offset == $i) : ?>selected="selected"<?php endif; ?> value="<?php echo $i; ?>"><?php echo $i; ?> Posts Old</option>
       
   125                     <?php endfor; ?>
       
   126                 </select>
       
   127 			</p>
       
   128         
       
   129             <p><label for="<?php echo $this->get_field_id('post_category'); ?>">Category
       
   130                <select size="1" class="widefat" id="<?php echo $this->get_field_id("post_category"); ?>" name="<?php echo $this->get_field_name("post_category"); ?>">
       
   131                     <option <?php if($post_count == 0){echo "selected=\"selected\"";} ?> value="0">All</option>
       
   132                     <?php
       
   133 							$category_args = array('hide_empty' => false);
       
   134                             $option_loop = get_categories($category_args);
       
   135                             foreach($option_loop as $option_label => $value)
       
   136                                 { 	
       
   137                                     // Set the $value and $label for the options
       
   138                                     $use_value =  $value->slug;
       
   139                                     $label =  $value->cat_name;
       
   140                                     //If this option == the value we set above, select it
       
   141                                     if($use_value == $post_category)
       
   142                                         {$selected = " selected='selected' ";}
       
   143                                     else
       
   144                                         {$selected = " ";}
       
   145                     ?>
       
   146                                     <option <?php echo $selected; ?> value="<?php echo $use_value; ?>"><?php echo $label; ?></option>
       
   147                     <?php 
       
   148                                 }
       
   149                     ?>
       
   150                 </select>
       
   151 			</p>
       
   152 <?php 
       
   153 	} // form
       
   154 
       
   155 }// class
       
   156 
       
   157 //This sample widget can then be registered in the widgets_init hook:
       
   158 
       
   159 // register FooWidget widget
       
   160 add_action('widgets_init', create_function('', 'return register_widget("four_block_widget");'));
       
   161 
       
   162 ?>