Advertisement
Guest User

hotel-listing

a guest
Sep 26th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 8.70 KB | None | 0 0
  1. <?php
  2. add_shortcode( 'themeum_hotel_listing', function($atts, $content = null) {
  3.  
  4.     extract(shortcode_atts(array(
  5.         'category_hotel'                =>  '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_hotel == '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_hotel),
  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.             $output .= '<a class="package-list-button" href="'.get_the_permalink($mpost->ID).'">'.__('View Details','themeum-core').'</a>';
  65.             $output .= '</div>'; //package-img-wrap
  66.             $output .= '<div class="package-list-content">';
  67.  
  68.             $hotel_price_min  = '';
  69.             if (!empty($roominfo)) {
  70.                 $temp_prices = array();
  71.  
  72.                 foreach ($roominfo as $hotel_price) {
  73.                     if (isset($hotel_price['themeum_roomprice'])) {
  74.                         $temp_prices[] = $hotel_price['themeum_roomprice'];
  75.                     }
  76.                 }
  77.  
  78.                 if (!empty($temp_prices)) {
  79.                     if (!get_theme_mod( 'currency_right' )) {
  80.                         $hotel_price_min = get_theme_mod( 'other_currency', '$' ).min($temp_prices);
  81.                     } else {
  82.                         $hotel_price_min = min($temp_prices).get_theme_mod( 'other_currency', '$' );
  83.                     }
  84.                    
  85.                 }
  86.  
  87.  
  88.             }
  89.             $output .= '<h3 class="package-list-title"><a href="'.get_the_permalink($mpost->ID).'">'.get_the_title($mpost->ID).'</a></h3>';
  90.             if ($hotelduration != '' || $hotel_price_min != '' ) {
  91.                 $output .= '<p class="package-list-duration">' .__('Start from','themeum-core').' '.$hotel_price_min. '/'. $hotelduration .'</p>';
  92.             }
  93.             $output .= '</div>';//package-list-content
  94.             $output .= '</div>';//package-list-wrap
  95.         } elseif ( $layoutstyle == 'style3' ) {
  96.             $output .= '<div class="package-list-wrap package-list-wrap-v3">';
  97.             $output .= '<div class="package-img-wrap">';
  98.             $output .= get_the_post_thumbnail($mpost->ID,'travelkit-medium', array('class' => 'img-responsive'));
  99.             $output .= '<a class="package-list-button" href="'.get_the_permalink($mpost->ID).'">'.__('View Details','themeum-core').'</a>';
  100.             $output .= '</div>'; //package-img-wrap
  101.             $output .= '<div class="package-list-content">';
  102.  
  103.             $hotel_price_min  = '';
  104.             if (!empty($roominfo)) {
  105.                 $temp_prices = array();
  106.  
  107.                 foreach ($roominfo as $hotel_price) {
  108.                     if (isset($hotel_price['themeum_roomprice'])) {
  109.                         $temp_prices[] = $hotel_price['themeum_roomprice'];
  110.                     }
  111.                 }
  112.  
  113.                 if (!empty($temp_prices)) {
  114.                     if (!get_theme_mod( 'currency_right' )) {
  115.                         $hotel_price_min = get_theme_mod( 'other_currency', '$' ).min($temp_prices);
  116.                     } else {
  117.                         $hotel_price_min = min($temp_prices).get_theme_mod( 'other_currency', '$' );
  118.                     }
  119.                 }
  120.  
  121.  
  122.             }
  123.             $output .= '<h3 class="package-list-title"><a href="'.get_the_permalink($mpost->ID).'">'.get_the_title($mpost->ID).'</a></h3>';
  124.             if ($hotelduration != '' || $hotel_price_min != '' ) {
  125.                 $output .= '<p class="package-list-duration">' .__('Start from','themeum-core').' '.$hotel_price_min. '/'. $hotelduration .'</p>';
  126.             }
  127.             $output .= '</div>';//package-list-content
  128.             $output .= '</div>';//package-list-wrap
  129.         } else{
  130.             $output .= '<div class="package-list-wrap">';
  131.             $output .= get_the_post_thumbnail($mpost->ID,'travelkit-medium', array('class' => 'img-responsive'));
  132.             $output .= '<div class="package-list-content">';
  133.  
  134.             $hotel_price_min  = '';
  135.             if (!empty($roominfo)) {
  136.                 $temp_prices = array();
  137.  
  138.                 foreach ($roominfo as $hotel_price) {
  139.                     if (isset($hotel_price['themeum_roomprice'])) {
  140.                         $temp_prices[] = $hotel_price['themeum_roomprice'];
  141.                     }
  142.                 }
  143.  
  144.                 if (!empty($temp_prices)) {
  145.                     if (!get_theme_mod( 'currency_right' )) {
  146.                         $hotel_price_min = get_theme_mod( 'other_currency', '$' ).min($temp_prices);
  147.                     } else {
  148.                         $hotel_price_min = min($temp_prices).get_theme_mod( 'other_currency', '$' );
  149.                     }
  150.                 }
  151.  
  152.  
  153.             }
  154.             if ($hotelduration != '' || $hotel_price_min != '' ) {
  155.                 $output .= '<p class="package-list-duration">' .__('Start from','themeum-core').' '.$hotel_price_min. '/'. $hotelduration .'</p>';
  156.             }
  157.             $output .= '<h3 class="package-list-title"><a href="'.get_the_permalink($mpost->ID).'">'.get_the_title($mpost->ID).'</a></h3>';
  158.             $output .= '<a class="package-list-button" href="'.get_the_permalink($mpost->ID).'">'.__('View Details','themeum-core').'</a>';
  159.             $output .= '</div>';//package-list-content
  160.             $output .= '</div>';//package-list-wrap
  161.         }
  162.         $output .= '</div>';//col-sm-6
  163.  
  164.     endforeach;
  165.     $output .= '</div>'; //row
  166.     wp_reset_postdata();
  167.     $output .= '</div>';//add-popular-tour-package
  168.  
  169.     //pagination
  170.     if($paginationen == 'yes') {
  171.         $args['posts_per_page'] = -1;
  172.         $total_post = get_posts( $args );
  173.         $var = $number;
  174.         if( $var == "" || $var == 0 ){
  175.             $total_post = 1;
  176.         }else{
  177.             $total_post = ceil( count($total_post)/(int)$var );
  178.         }
  179.  
  180.         $output .= '<div class="themeum-pagination">';
  181.         $big = 999999999; // need an unlikely integer
  182.         $output .= paginate_links( array(
  183.             'type'               => 'list',
  184.             'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) )),
  185.             'format' => '?paged=%#%',
  186.             'current' => $pagenum,
  187.             'total' => $total_post
  188.             ) );
  189.             $output .= '</div>'; //pagination-in
  190.         }
  191.     }
  192.     $post = $temp_post;
  193.  
  194.     return $output;
  195.  
  196. });
  197.  
  198.  
  199. //Visual Composer
  200. if (class_exists('WPBakeryVisualComposerAbstract')) {
  201.     vc_map(array(
  202.         "name"              => esc_html__("Hotel Listing", 'themeum-core'),
  203.         "base"              => "themeum_hotel_listing",
  204.         'icon'              => 'icon-thm-hotel',
  205.         "class"             => "",
  206.         "description"       => esc_html__("Widget Title Heading", 'themeum-core'),
  207.         "category"          => esc_html__('Travelkit', 'themeum-core'),
  208.         "params"            => array(
  209.             array(
  210.                 "type"          => "dropdown",
  211.                 "heading"       => esc_html__("Layout style", "themeum-core"),
  212.                 "param_name"    => "layoutstyle",
  213.                 "value"         => array('Select'=>'','Style 1'=>'style1','Style 2'=>'style2','Style 3'=>'style3'),
  214.                 ),
  215.  
  216.             array(
  217.                 "type"          => "dropdown",
  218.                 "heading"       => esc_html__("Category Filter", 'themeum-core'),
  219.                 "param_name"    => "category_hotel",
  220.                 "value"         => themeum_cat_list('hotel-category'),
  221.             ),
  222.  
  223.             array(
  224.                 "type"          => "textfield",
  225.                 "heading"       => esc_html__("Number of items", 'themeum-core'),
  226.                 "param_name"    => "number",
  227.                 "value"         => "6",
  228.             ),
  229.  
  230.             array(
  231.                 "type"          => "dropdown",
  232.                 "heading"       => esc_html__("Number Of Column", "themeum-core"),
  233.                 "param_name"    => "column",
  234.                 "value"         => array('Select'=>'','column 2'=>'6','column 3'=>'4','column 4'=>'3'),
  235.             ),
  236.  
  237.             array(
  238.                 "type"          => "dropdown",
  239.                 "heading"       => esc_html__("Order", 'themeum-core'),
  240.                 "param_name"    => "order",
  241.                 "value"         => array('None'=>'','DESC'=>'DESC','ASC'=>'ASC'),
  242.             ),
  243.  
  244.             array(
  245.                 "type"          => "dropdown",
  246.                 "heading"       => esc_html__("OderBy", 'themeum-core'),
  247.                 "param_name"    => "order_by",
  248.                 "value"         => array('None'=>'','Date'=>'date','Title'=>'title','Modified'=>'modified','Author'=>'author','Random'=>'rand'),
  249.             ),
  250.  
  251.             array(
  252.                 "type"          => "dropdown",
  253.                 "heading"       => esc_html__("Pagination", 'themeum-core'),
  254.                 "param_name"    => "paginationen",
  255.                 "value"         => array('None'=>'','YES'=>'yes','NO'=>'no'),
  256.             ),
  257.  
  258.             array(
  259.                 "type"          => "textfield",
  260.                 "heading"       => esc_html__("Custom Class", 'themeum-core'),
  261.                 "param_name"    => "class",
  262.                 "value"         => "",
  263.             ),
  264.  
  265.             )
  266.  
  267.         ));
  268.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement