Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action('widgets_init','wbr_project_widget1',99);
- function wbr_project_widget1(){
- unregister_widget('wdl_product_widget');
- return register_widget('wbr_project_widget1');
- }
- class wbr_project_widget1 extends WP_Widget{
- function __construct() {
- parent::__construct(
- 'wbr_project_widget', // Base ID
- __('WBR : Product Category Widget', 'spasalon'), // Name
- array( 'description' => __( 'Product Category Widget', 'spasalon'), ) // Args
- );
- }
- public function widget( $args , $instance ) {
- $instance['project_cat'] = ( isset($instance['project_cat'] ) ? $instance['project_cat'] : '' );
- echo $args['before_widget']; ?>
- <div id="products-<?php echo $args['widget_id']; ?>" class="carousel slide row products" data-ride="carousel" data-type="multi">
- <div class="carousel-inner">
- <?php
- $count_posts = wp_count_posts( 'spa_products')->publish;
- $arg1 = array(
- 'post_type' => 'spa_products',
- 'tax_query' => array( array(
- 'taxonomy' => 'product_categories',
- 'field' => 'term_id',
- 'terms' => $instance['project_cat'] ) ),
- 'posts_per_page' => $count_posts
- );
- $loop = new WP_Query( $arg1 );
- $i=1;
- if($loop->have_posts() ):
- while ( $loop->have_posts() ) : $loop->the_post();
- $my_meta = get_post_meta(get_the_ID(),'_my_meta',TRUE);
- if($my_meta['link']!='')
- { $meta_value_link = $my_meta['link']; }
- else
- { $meta_value_link = get_permalink(); }
- if(isset($my_meta['check']))
- { $target ='target="_blank"'; } else { $target ='target="_self"'; }
- ?>
- <div class="item <?php echo ($i==1?'active':''); $i++; ?>">
- <div class="column">
- <div class="product-view">
- <?php if( has_post_thumbnail() ): ?>
- <a href="<?php echo $meta_value_link; ?>" <?php echo $target; ?> title="<?php the_title(); ?>">
- <?php the_post_thumbnail('large'); ?>
- </a>
- <?php endif; ?>
- <span class="prt-detail">
- <h4>
- <a href="<?php echo $meta_value_link; ?>" <?php echo $target; ?> title="<?php the_title(); ?>">
- <?php the_title(); ?>
- </a>
- </h4>
- <p>
- <?php
- if( isset( $my_meta['description'] ) )
- echo get_homepage_product_excerpt($my_meta['description']);
- ?>
- </p>
- </span>
- </div>
- </div>
- </div>
- <?php
- endwhile;
- wp_reset_postdata();
- endif;
- ?>
- </div>
- <?php if( $loop->post_count > 5 ): ?>
- <ul class="direction-nav">
- <a class="prev" href="#products-<?php echo $args['widget_id']; ?>" data-slide="prev"></a>
- <a class="next" href="#products-<?php echo $args['widget_id']; ?>" data-slide="next"></a>
- </ul>
- <?php endif; ?>
- <script>
- // Carousel Products Scroll Js
- jQuery(function($) {
- $('#products-<?php echo $args['widget_id']; ?>').carousel({
- interval: false,
- wrap: true // Case true:- alternate item scroll & Case false:- After scrolling stop item scroll
- })
- $('#products-<?php echo $args['widget_id']; ?> .item').each(function(){
- var itemToClone = $(this);
- for (var i=1;i<5;i++) {
- itemToClone = itemToClone.next();
- // wrap around if at end of item collection
- if (!itemToClone.length) {
- itemToClone = $(this).siblings(':first');
- }
- // grab item, clone, add marker class, add to collection
- itemToClone.children(':first-child').clone()
- .addClass("cloneditem-"+(i))
- .appendTo($(this));
- }
- });
- });
- </script>
- </div>
- <?php echo $args['after_widget'];
- }
- public function form( $instance ) {
- $instance['project_cat'] = isset($instance['project_cat']) ? $instance['project_cat'] : '';
- ?>
- <p>
- <label for="<?php echo $this->get_field_id( 'project_cat' ); ?>"><?php _e( 'Select Pages','spasalon' ); ?></label>
- <select class="widefat" id="<?php echo $this->get_field_id( 'project_cat' ); ?>" name="<?php echo $this->get_field_name( 'project_cat' ); ?>">
- <option value>---<?php _e( 'Select','spasalon' ); ?>---</option>
- <?php
- $args = array("hide_empty" => 0,
- "type" => "spa_products",
- "orderby" => "name",
- "order" => "ASC" ,
- 'taxonomy'=> 'product_categories'
- );
- $project_cat = $instance['project_cat'];
- $cats = get_categories($args);
- foreach ( $cats as $cat ) {
- $option = '<option value="' . $cat->term_id . '" ';
- $option .= ( $cat->term_id == $project_cat ) ? 'selected="selected"' : '';
- $option .= '>';
- $option .= $cat->name;
- $option .= '</option>';
- echo $option;
- }
- ?>
- </select>
- <br/>
- </p>
- <?php
- }
- public function update( $new_instance, $old_instance ) {
- $instance = array();
- $instance['project_cat'] = ( ! empty( $new_instance['project_cat'] ) ) ? $new_instance['project_cat'] : '';
- return $instance;
- }
- }
Add Comment
Please, Sign In to add comment