Guest User

Untitled

a guest
Mar 20th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.32 KB | None | 0 0
  1.  
  2. add_action('widgets_init','wbr_project_widget1',99);
  3. function wbr_project_widget1(){
  4. unregister_widget('wdl_product_widget');
  5. return register_widget('wbr_project_widget1');
  6. }
  7.  
  8. class wbr_project_widget1 extends WP_Widget{
  9.  
  10. function __construct() {
  11. parent::__construct(
  12. 'wbr_project_widget', // Base ID
  13. __('WBR : Product Category Widget', 'spasalon'), // Name
  14. array( 'description' => __( 'Product Category Widget', 'spasalon'), ) // Args
  15. );
  16. }
  17.  
  18.  
  19. public function widget( $args , $instance ) {
  20.  
  21. $instance['project_cat'] = ( isset($instance['project_cat'] ) ? $instance['project_cat'] : '' );
  22.  
  23. echo $args['before_widget']; ?>
  24.  
  25. <div id="products-<?php echo $args['widget_id']; ?>" class="carousel slide row products" data-ride="carousel" data-type="multi">
  26.  
  27. <div class="carousel-inner">
  28.  
  29. <?php
  30.  
  31. $count_posts = wp_count_posts( 'spa_products')->publish;
  32.  
  33. $arg1 = array(
  34.  
  35. 'post_type' => 'spa_products',
  36.  
  37. 'tax_query' => array( array(
  38.  
  39. 'taxonomy' => 'product_categories',
  40.  
  41. 'field' => 'term_id',
  42.  
  43. 'terms' => $instance['project_cat'] ) ),
  44.  
  45. 'posts_per_page' => $count_posts
  46.  
  47. );
  48.  
  49. $loop = new WP_Query( $arg1 );
  50.  
  51. $i=1;
  52.  
  53. if($loop->have_posts() ):
  54.  
  55. while ( $loop->have_posts() ) : $loop->the_post();
  56.  
  57. $my_meta = get_post_meta(get_the_ID(),'_my_meta',TRUE);
  58.  
  59. if($my_meta['link']!='')
  60. { $meta_value_link = $my_meta['link']; }
  61. else
  62. { $meta_value_link = get_permalink(); }
  63.  
  64. if(isset($my_meta['check']))
  65. { $target ='target="_blank"'; } else { $target ='target="_self"'; }
  66. ?>
  67.  
  68. <div class="item <?php echo ($i==1?'active':''); $i++; ?>">
  69.  
  70. <div class="column">
  71.  
  72. <div class="product-view">
  73.  
  74. <?php if( has_post_thumbnail() ): ?>
  75.  
  76. <a href="<?php echo $meta_value_link; ?>" <?php echo $target; ?> title="<?php the_title(); ?>">
  77. <?php the_post_thumbnail('large'); ?>
  78. </a>
  79.  
  80. <?php endif; ?>
  81.  
  82. <span class="prt-detail">
  83.  
  84. <h4>
  85. <a href="<?php echo $meta_value_link; ?>" <?php echo $target; ?> title="<?php the_title(); ?>">
  86. <?php the_title(); ?>
  87. </a>
  88. </h4>
  89.  
  90. <p>
  91. <?php
  92. if( isset( $my_meta['description'] ) )
  93. echo get_homepage_product_excerpt($my_meta['description']);
  94. ?>
  95. </p>
  96.  
  97. </span>
  98.  
  99. </div>
  100.  
  101. </div>
  102.  
  103. </div>
  104.  
  105. <?php
  106.  
  107. endwhile;
  108.  
  109. wp_reset_postdata();
  110.  
  111. endif;
  112.  
  113. ?>
  114.  
  115. </div>
  116.  
  117. <?php if( $loop->post_count > 5 ): ?>
  118.  
  119. <ul class="direction-nav">
  120. <a class="prev" href="#products-<?php echo $args['widget_id']; ?>" data-slide="prev"></a>
  121. <a class="next" href="#products-<?php echo $args['widget_id']; ?>" data-slide="next"></a>
  122. </ul>
  123.  
  124. <?php endif; ?>
  125.  
  126. <script>
  127. // Carousel Products Scroll Js
  128.  
  129. jQuery(function($) {
  130.  
  131. $('#products-<?php echo $args['widget_id']; ?>').carousel({
  132. interval: false,
  133. wrap: true // Case true:- alternate item scroll & Case false:- After scrolling stop item scroll
  134. })
  135.  
  136. $('#products-<?php echo $args['widget_id']; ?> .item').each(function(){
  137. var itemToClone = $(this);
  138.  
  139. for (var i=1;i<5;i++) {
  140. itemToClone = itemToClone.next();
  141.  
  142. // wrap around if at end of item collection
  143. if (!itemToClone.length) {
  144. itemToClone = $(this).siblings(':first');
  145. }
  146.  
  147. // grab item, clone, add marker class, add to collection
  148. itemToClone.children(':first-child').clone()
  149. .addClass("cloneditem-"+(i))
  150. .appendTo($(this));
  151. }
  152. });
  153.  
  154. });
  155. </script>
  156. </div>
  157.  
  158. <?php echo $args['after_widget'];
  159. }
  160.  
  161. public function form( $instance ) {
  162. $instance['project_cat'] = isset($instance['project_cat']) ? $instance['project_cat'] : '';
  163. ?>
  164.  
  165. <p>
  166. <label for="<?php echo $this->get_field_id( 'project_cat' ); ?>"><?php _e( 'Select Pages','spasalon' ); ?></label>
  167. <select class="widefat" id="<?php echo $this->get_field_id( 'project_cat' ); ?>" name="<?php echo $this->get_field_name( 'project_cat' ); ?>">
  168. <option value>---<?php _e( 'Select','spasalon' ); ?>---</option>
  169. <?php
  170.  
  171. $args = array("hide_empty" => 0,
  172. "type" => "spa_products",
  173. "orderby" => "name",
  174. "order" => "ASC" ,
  175. 'taxonomy'=> 'product_categories'
  176. );
  177.  
  178. $project_cat = $instance['project_cat'];
  179.  
  180. $cats = get_categories($args);
  181.  
  182. foreach ( $cats as $cat ) {
  183. $option = '<option value="' . $cat->term_id . '" ';
  184. $option .= ( $cat->term_id == $project_cat ) ? 'selected="selected"' : '';
  185. $option .= '>';
  186. $option .= $cat->name;
  187. $option .= '</option>';
  188. echo $option;
  189. }
  190. ?>
  191.  
  192. </select>
  193. <br/>
  194.  
  195. </p>
  196.  
  197. <?php
  198. }
  199.  
  200. public function update( $new_instance, $old_instance ) {
  201.  
  202. $instance = array();
  203. $instance['project_cat'] = ( ! empty( $new_instance['project_cat'] ) ) ? $new_instance['project_cat'] : '';
  204.  
  205. return $instance;
  206. }
  207. }
Add Comment
Please, Sign In to add comment