Advertisement
fahimmurshed

hotel-listing

Dec 30th, 2019
459
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 9.33 KB | None | 0 0
  1. <?php
  2. add_shortcode( 'themeum_hotel_listing', function($atts, $content = null) {
  3.  
  4.     extract(shortcode_atts(array(
  5.         'category_package'              =>  'themeumall',
  6.         'number'                        => '6',
  7.         'column'                        => '4',
  8.         'layoutstyle'                   => 'style1',
  9.         'order_by'                      => 'date',
  10.         'paginationen'                  => 'no',
  11.         'order'                         => 'DESC',
  12.         'class'                         => '',
  13.     ), $atts));
  14.  
  15.     global $post;
  16.  
  17.     $posts = 0;
  18.     $temp_post = $post;
  19.     $output = $args = '';
  20.     $pagenum = max( 1, get_query_var('paged') );
  21.  
  22.     // The Query
  23.     if( $category_package == 'themeumall' ){
  24.         $args = array(
  25.             'post_type' => 'hotel',
  26.             'order' => esc_attr($order),
  27.             'orderby' => esc_attr($order_by),
  28.             'posts_per_page' => esc_attr($number),
  29.             'paged' => $pagenum
  30.         );
  31.     }else{
  32.         $args = array(
  33.             'post_type' => 'hotel',
  34.             'order' => 'DESC',
  35.             'tax_query' => array(
  36.                 array(
  37.                     'taxonomy' => 'hotel-category',
  38.                     'field'    => 'slug',
  39.                     'terms'    => esc_attr($category_package),
  40.                 ),
  41.             ),
  42.             'order' => esc_attr($order),
  43.             'orderby' => esc_attr($order_by),
  44.             'posts_per_page' => esc_attr($number),
  45.             'paged' => $pagenum
  46.         );
  47.     }
  48.  
  49.     $posts = get_posts( $args );
  50.  
  51.     if(count($posts)>0){
  52.         // The Loop
  53.         $output .= '<div class="add-popular-tour-package">';
  54.         $output .= '<div class="row">';
  55.         foreach ($posts as $key=>$mpost): setup_postdata($mpost);
  56.  
  57.         $hotelduration  = get_post_meta($mpost->ID,'themeum_hotelduration',true);
  58.         $roominfo  = get_post_meta($mpost->ID,'themeum_room_info',true);
  59.         $output .= '<div class="col-sm-6 col-md-'.esc_attr($column).'">';
  60.         if ( $layoutstyle == 'style2' ) {
  61.             $output .= '<div class="package-list-wrap package-list-wrap-v2">';
  62.             $output .= '<div class="package-img-wrap">';
  63.             $output .= get_the_post_thumbnail($mpost->ID,'travelkit-medium', array('class' => 'img-responsive'));
  64.  
  65.             $hotel_book_btn = get_theme_mod('hotel_booknow_btn');
  66.             if (isset($hotel_book_btn) && $hotel_book_btn != '') {
  67.                 $output .= '<a class="package-list-button" href="'.get_the_permalink($mpost->ID).'">'.$hotel_book_btn.'</a>';
  68.             }else {
  69.                 $output .= '<a class="package-list-button" href="'.get_the_permalink($mpost->ID).'">'.__('View Details','themeum-core').'</a>';
  70.             }
  71.  
  72.             $output .= '</div>'; //package-img-wrap
  73.             $output .= '<div class="package-list-content">';
  74.  
  75.             $hotel_price_min  = '';
  76.             if (!empty($roominfo)) {
  77.                 $temp_prices = array();
  78.  
  79.                 foreach ($roominfo as $hotel_price) {
  80.                     if (isset($hotel_price['themeum_roomprice'])) {
  81.                         $temp_prices[] = $hotel_price['themeum_roomprice'];
  82.                     }
  83.                 }
  84.  
  85.                 if (!empty($temp_prices)) {
  86.                     if (!get_theme_mod( 'currency_right' )) {
  87.                         $hotel_price_min = get_theme_mod( 'other_currency', '$' ).min($temp_prices);
  88.                     } else {
  89.                         $hotel_price_min = min($temp_prices).get_theme_mod( 'other_currency', '$' );
  90.                     }
  91.                    
  92.                 }
  93.  
  94.  
  95.             }
  96.             $output .= '<h3 class="package-list-title"><a href="'.get_the_permalink($mpost->ID).'">'.get_the_title($mpost->ID).'</a></h3>';
  97.             if ($hotelduration != '' || $hotel_price_min != '' ) {
  98.                 $output .= '<p class="package-list-duration">' .__('Start from','themeum-core').' '.$hotel_price_min. '/'. $hotelduration .'</p>';
  99.             }
  100.             $output .= '</div>';//package-list-content
  101.             $output .= '</div>';//package-list-wrap
  102.         } elseif ( $layoutstyle == 'style3' ) {
  103.             $output .= '<div class="package-list-wrap package-list-wrap-v3">';
  104.             $output .= '<div class="package-img-wrap">';
  105.             $output .= get_the_post_thumbnail($mpost->ID,'travelkit-medium', array('class' => 'img-responsive'));
  106.             $hotel_book_btn = get_theme_mod('hotel_booknow_btn');
  107.             if (isset($hotel_book_btn) && $hotel_book_btn != '') {
  108.                 $output .= '<a class="package-list-button" href="'.get_the_permalink($mpost->ID).'">'.$hotel_book_btn.'</a>';
  109.             }else {
  110.                 $output .= '<a class="package-list-button" href="'.get_the_permalink($mpost->ID).'">'.__('View Details','themeum-core').'</a>';
  111.             }
  112.             $output .= '</div>'; //package-img-wrap
  113.             $output .= '<div class="package-list-content">';
  114.  
  115.             $hotel_price_min  = '';
  116.             if (!empty($roominfo)) {
  117.                 $temp_prices = array();
  118.  
  119.                 foreach ($roominfo as $hotel_price) {
  120.                     if (isset($hotel_price['themeum_roomprice'])) {
  121.                         $temp_prices[] = $hotel_price['themeum_roomprice'];
  122.                     }
  123.                 }
  124.  
  125.                 if (!empty($temp_prices)) {
  126.                     if (!get_theme_mod( 'currency_right' )) {
  127.                         $hotel_price_min = get_theme_mod( 'other_currency', '$' ).min($temp_prices);
  128.                     } else {
  129.                         $hotel_price_min = min($temp_prices).get_theme_mod( 'other_currency', '$' );
  130.                     }
  131.                 }
  132.  
  133.  
  134.             }
  135.             $output .= '<h3 class="package-list-title"><a href="'.get_the_permalink($mpost->ID).'">'.get_the_title($mpost->ID).'</a></h3>';
  136.             if ($hotelduration != '' || $hotel_price_min != '' ) {
  137.                 $output .= '<p class="package-list-duration">' .__('Start from','themeum-core').' '.$hotel_price_min. '/'. $hotelduration .'</p>';
  138.             }
  139.             $output .= '</div>';//package-list-content
  140.             $output .= '</div>';//package-list-wrap
  141.         } else{
  142.             $output .= '<div class="package-list-wrap">';
  143.             $output .= get_the_post_thumbnail($mpost->ID,'travelkit-medium', array('class' => 'img-responsive'));
  144.             $output .= '<div class="package-list-content">';
  145.  
  146.             $hotel_price_min  = '';
  147.             if (!empty($roominfo)) {
  148.                 $temp_prices = array();
  149.  
  150.                 foreach ($roominfo as $hotel_price) {
  151.                     if (isset($hotel_price['themeum_roomprice'])) {
  152.                         $temp_prices[] = $hotel_price['themeum_roomprice'];
  153.                     }
  154.                 }
  155.  
  156.                 if (!empty($temp_prices)) {
  157.                     if (!get_theme_mod( 'currency_right' )) {
  158.                         $hotel_price_min = get_theme_mod( 'other_currency', '$' ).min($temp_prices);
  159.                     } else {
  160.                         $hotel_price_min = min($temp_prices).get_theme_mod( 'other_currency', '$' );
  161.                     }
  162.                 }
  163.  
  164.  
  165.             }
  166.             if ($hotelduration != '' || $hotel_price_min != '' ) {
  167.                 $output .= '<p class="package-list-duration">' .__('Start from','themeum-core').' '.$hotel_price_min. '/'. $hotelduration .'</p>';
  168.             }
  169.             $output .= '<h3 class="package-list-title"><a href="'.get_the_permalink($mpost->ID).'">'.get_the_title($mpost->ID).'</a></h3>';
  170.             $hotel_book_btn = get_theme_mod('hotel_booknow_btn');
  171.             if (isset($hotel_book_btn) && $hotel_book_btn != '') {
  172.                 $output .= '<a class="package-list-button" href="'.get_the_permalink($mpost->ID).'">'.$hotel_book_btn.'</a>';
  173.             }else {
  174.                 $output .= '<a class="package-list-button" href="'.get_the_permalink($mpost->ID).'">'.__('View Details','themeum-core').'</a>';
  175.             }
  176.             $output .= '</div>';//package-list-content
  177.             $output .= '</div>';//package-list-wrap
  178.         }
  179.         $output .= '</div>';//col-sm-6
  180.  
  181.     endforeach;
  182.     $output .= '</div>'; //row
  183.     wp_reset_postdata();
  184.     $output .= '</div>';//add-popular-tour-package
  185.  
  186.     //pagination
  187.     if($paginationen == 'yes') {
  188.         $args['posts_per_page'] = -1;
  189.         $total_post = get_posts( $args );
  190.         $var = $number;
  191.         if( $var == "" || $var == 0 ){
  192.             $total_post = 1;
  193.         }else{
  194.             $total_post = ceil( count($total_post)/(int)$var );
  195.         }
  196.  
  197.         $output .= '<div class="themeum-pagination">';
  198.         $big = 999999999; // need an unlikely integer
  199.         $output .= paginate_links( array(
  200.             'type'               => 'list',
  201.             'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) )),
  202.             'format' => '?paged=%#%',
  203.             'current' => $pagenum,
  204.             'total' => $total_post
  205.             ) );
  206.             $output .= '</div>'; //pagination-in
  207.         }
  208.     }
  209.     $post = $temp_post;
  210.  
  211.     return $output;
  212.  
  213. });
  214.  
  215.  
  216. //Visual Composer
  217. if (class_exists('WPBakeryVisualComposerAbstract')) {
  218.     vc_map(array(
  219.         "name" => esc_html__("Hotel Listing", 'themeum-core'),
  220.         "base" => "themeum_hotel_listing",
  221.         'icon' => 'icon-thm-hotel',
  222.         "class" => "",
  223.         "description" => esc_html__("Widget Title Heading", 'themeum-core'),
  224.         "category" => esc_html__('Travelkit', 'themeum-core'),
  225.         "params" => array(
  226.             array(
  227.                 "type" => "dropdown",
  228.                 "heading" => esc_html__("Layout style", "themeum-core"),
  229.                 "param_name" => "layoutstyle",
  230.                 "value" => array('Select'=>'','Style 1'=>'style1','Style 2'=>'style2','Style 3'=>'style3'),
  231.                 ),
  232.  
  233.             array(
  234.                 "type" => "dropdown",
  235.                 "heading" => esc_html__("Category Filter", 'themeum-core'),
  236.                 "param_name" => "hotel-category",
  237.                 "value" => themeum_cat_list('hotel-category'),
  238.             ),
  239.  
  240.             array(
  241.                 "type" => "textfield",
  242.                 "heading" => esc_html__("Number of items", 'themeum-core'),
  243.                 "param_name" => "number",
  244.                 "value" => "6",
  245.             ),
  246.  
  247.             array(
  248.                 "type" => "dropdown",
  249.                 "heading" => esc_html__("Number Of Column", "themeum-core"),
  250.                 "param_name" => "column",
  251.                 "value" => array('Select'=>'','column 2'=>'6','column 3'=>'4','column 4'=>'3'),
  252.             ),
  253.  
  254.             array(
  255.                 "type" => "dropdown",
  256.                 "heading" => esc_html__("Order", 'themeum-core'),
  257.                 "param_name" => "order",
  258.                 "value" => array('None'=>'','DESC'=>'DESC','ASC'=>'ASC'),
  259.             ),
  260.  
  261.             array(
  262.                 "type" => "dropdown",
  263.                 "heading" => esc_html__("OderBy", 'themeum-core'),
  264.                 "param_name" => "order_by",
  265.                 "value" => array('None'=>'','Date'=>'date','Title'=>'title','Modified'=>'modified','Author'=>'author','Random'=>'rand'),
  266.             ),
  267.  
  268.             array(
  269.                 "type" => "dropdown",
  270.                 "heading" => esc_html__("Pagination", 'themeum-core'),
  271.                 "param_name" => "paginationen",
  272.                 "value" => array('None'=>'','YES'=>'yes','NO'=>'no'),
  273.             ),
  274.  
  275.             array(
  276.                 "type" => "textfield",
  277.                 "heading" => esc_html__("Custom Class", 'themeum-core'),
  278.                 "param_name" => "class",
  279.                 "value" => "",
  280.             ),
  281.  
  282.             )
  283.  
  284.         ));
  285.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement