Marcos_Alexandre

FIlter Category Progress Map

Mar 14th, 2018
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.01 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * Limit excerpt to a number of characters
  5.  *
  6.  * @param string $excerpt
  7.  * @return string
  8.  */
  9. function custom_short_excerpt($excerpt){
  10.     return substr($excerpt, 0, 200);
  11. }
  12. add_filter('the_excerpt', 'custom_short_excerpt');
  13.  
  14.  
  15. /* Funtion Count Posts in Category */
  16.  
  17. function number_postpercat($idcat) {
  18.     global $wpdb;
  19.     $query = "SELECT count FROM $wpdb->term_taxonomy WHERE term_id = $idcat";
  20.     $num = $wpdb->get_col($query);
  21.     echo $num[0];
  22. }
  23.  
  24. /**
  25.  * Change the default settings of a map
  26.  *
  27.  * @since "Progress Map v3"
  28.  */
  29. function cspm_update_map_settings($map_settings, $map_id){
  30.  
  31.     if (!class_exists('CspmMainMap'))
  32.      return;
  33.    
  34.     $CspmMainMap = CspmMainMap::this();
  35.    
  36.     $fields_prefix = $CspmMainMap->metafield_prefix;
  37.    
  38.     if(is_tax() || is_category() || is_tag() || is_archive()){
  39.        
  40.         $queried_object = get_queried_object();
  41.  
  42.         $taxonomy = (isset($queried_object->taxonomy)) ? $queried_object->taxonomy : ''; // The taxonomy slug/name
  43.         $term_id = (isset($queried_object->term_id)) ? $queried_object->term_id : ''; // The term ID
  44.            
  45.         $map_settings[$fields_prefix.'_taxonomie_'.$taxonomy] = serialize(array($term_id));
  46.        
  47.     }
  48.    
  49.     return $map_settings;
  50.    
  51. }
  52. add_filter('cspm_map_settings', 'cspm_update_map_settings', 10, 2);
  53.  
  54.  
  55. /**
  56.  * List & Filter!
  57.  * This will change the content of the items displayed for the list
  58.  *
  59.  * @default_content | The default content when there's no custom content to display.
  60.  * @post_id | The ID of the post.
  61.  * @view | List view. Possible value are "list" & "grid".
  62.  * @filter | Whether the search filter is used or not. Possible values are "yes" and "no".
  63.  * @map_id | The ID of the map
  64.  * @latLng | The coordinates (Latitude & Longitude) of the post on the map. Laitude and Longitude separated by underscore, for example, (15.6540_50.54802)
  65.  *
  66.  */
  67. function cspml_change_list_items_content($default_content, $post_id, $view, $filter, $map_id, $latLng){
  68.  
  69.     global $post;
  70.  
  71.     $output = '';    
  72.  
  73.     $post_record = get_post( $post_id, ARRAY_A, 'display' );
  74.  
  75.     $output .= trim(preg_replace('/\s+/', ' ', $post_record['post_excerpt']));
  76.  
  77.         //$output .= do_shortcode('[star rating="5" max="2"]');
  78.         //$output .= do_shortcode('[contact-form-7 id="441" title="teste"]');
  79.  
  80.  
  81.         $price = get_field('ticket_price');
  82.         $time = get_field('time_duration_tour');
  83.         $from_tour = get_field('from_tour');
  84.         $link = get_post_permalink();
  85.         //$text_from =  esc_html( 'From', 'veditalia' );
  86.         $text_button =  esc_html( 'Book now', 'veditalia' );
  87.  
  88.         if ( $time != '' ): ?>
  89.  
  90.             <?php $output .= '<p class="time_duration_tour">'.$time.'</p>' ?>
  91.  
  92.         <?php
  93.  
  94.         endif;
  95.  
  96.         if ( $from_tour != '' ): ?>
  97.  
  98.             <?php $output .= '<p class="from_tour">' . $text_from . '&nbsp' . $from_tour . '</p>' ?>
  99.  
  100.         <?php
  101.  
  102.         endif;                           
  103.        
  104.  
  105.         if ( $price != '' ): ?>
  106.  
  107.             <?php $output .= '<p class="price-tour-p"><span class="price-tour">' . $price . '</span>' ?>
  108.         <?php
  109.  
  110.         endif; ?>
  111.  
  112.             <?php $output .= '<span class="btn-book"><a class="btn btn-primary pull-right btn-sm book-now" itemprop="url" href="'. $link . '">'.$text_button.'</a></span></p>' ?>
  113.  
  114.  
  115.         <?php
  116.  
  117.     wp_reset_postdata();
  118.  
  119.     return !empty($output) ? $output : $default_content;
  120.  
  121. }
  122. add_filter('cspml_list_item_description', 'cspml_change_list_items_content', 10, 6);
  123. add_filter('cspml_grid_item_description', 'cspml_change_list_items_content', 10, 6);
  124.  
  125.  
  126. /**
  127.  * List & Filter!
  128.  * This will change the content of the items displayed for the list
  129.  *
  130.  * @default_content | The default content when there's no custom content to display.
  131.  * @post_id | The ID of the post.
  132.  * @view | List view. Possible value are "list" & "grid".
  133.  * @filter | Whether the search filter is used or not. Possible values are "yes" and "no".
  134.  * @map_id | The ID of the map
  135.  * @latLng | The coordinates (Latitude & Longitude) of the post on the map. Laitude and Longitude separated by underscore, for example, (15.6540_50.54802)
  136.  *
  137.  */
  138. function cspml_change_image($default_content, $post_id, $view, $filter, $map_id, $latLng){
  139.  
  140.     global $post;
  141.  
  142.     $output = '';    
  143.  
  144.     $marker_img_array = apply_filters('cspml_post_thumb', wp_get_attachment_image_src( get_post_thumbnail_id($post_id), 'cspml-listings-thumbnail' ), $post_id);
  145.  
  146.     //$output .= trim(preg_replace('/\s+/', ' ', $post_record['post_excerpt']));
  147.     //$marker_img = isset($marker_img_array[0]) ? $marker_img_array[0] : apply_filters('cspml_empty_thumb_img', $this->plugin_url.'img/thumbnail.jpg', str_replace('map', '', $map_id));
  148.  
  149.         /*
  150.          * Item's Label's */
  151.  
  152.        
  153.  
  154.         if( have_rows('tag_tour') !='' ): ?>
  155.  
  156.             <?php while( have_rows('tag_tour') ): the_row();
  157.  
  158.                 $tag_type = get_sub_field('tag_type');
  159.                 $tag_discount_value = get_sub_field('tag_discount_value'); ?>                                                              
  160.  
  161.                 <?php if( get_sub_field('tag_type') == 'Top Attraction' ): ?>
  162.  
  163.                     <?php $output .= '<div class="tag tag-top-attraction">' ?>
  164.                            
  165.                         <?php $output .= '<span class="discounts"></span> '.$tag_type.'</span>' ?>
  166.  
  167.                     <?php $output .= '</div>'?>
  168.  
  169.                 <?php elseif( get_sub_field('tag_type') == 'Special Offer' ): ?>
  170.  
  171.                     <?php $output .= '<div class="tag tag-special-offer">' ?>
  172.                            
  173.                         <?php $output .= '<span class="discounts"></span> '.$tag_type.'</span>' ?>
  174.  
  175.                     <?php $output .= '</div>'?>
  176.  
  177.                 <?php elseif( get_sub_field('tag_type') == 'Best Seller' ): ?>
  178.  
  179.                     <?php $output .= '<div class="tag tag-best-seller">' ?>
  180.                            
  181.                         <?php $output .= '<span class="discounts"></span> '.$tag_type.'</span>' ?>
  182.  
  183.                     <?php $output .= '</div>' ?>
  184.  
  185.                 <?php elseif( get_sub_field('tag_type') == 'Default' ): ?>
  186.  
  187.                     <?php $output .= '<div class="tag-discounts"></div>' ?>
  188.  
  189.                 <?php elseif( get_sub_field('tag_type') == 'Discount' ): ?>
  190.  
  191.                     <?php if($tag_discount_value !=''):
  192.  
  193.                         $off_simbol = esc_html( '% ', 'veditalia' );
  194.                         $off_text = esc_html( 'OFF ', 'veditalia' ); ?>
  195.  
  196.  
  197.                         <?php $output .= '<div class="tag tag-discont">' ?>
  198.                                
  199.                             <?php $output .= '<span class="discounts"></span> '.$tag_discount_value.'</span><span class="after-discounts-1">'.$off_simbol.'</span><span class="after-discounts-2">'.$off_text.'</span>' ?>
  200.  
  201.                         <?php $output .= '</div>' ?>
  202.  
  203.                     <?php endif;
  204.  
  205.                 endif;
  206.  
  207.             endwhile;
  208.  
  209.         endif;
  210.  
  211.  
  212.    
  213.         /**
  214.          * Item's Gallery */
  215.  
  216.        
  217.    
  218.         $images = get_field( 'gallery_tour' );
  219.  
  220.  
  221.         if( $images !='' ):
  222.  
  223.             $output .= '<div id="slider" class="flexslider flexslider-tour" itemscope ><ul class="slides">' ?>
  224.  
  225.             <?php foreach( $images as $image ):
  226.  
  227.                 $carousel = $image['sizes']['tour-home'];
  228.                 $alt = $image['alt'];
  229.  
  230.                     $output .= '<li><figure><img src="'.$carousel.'" alt="'.$alt.'" class="thumb img-responsive" /></figure></li>' ?>
  231.  
  232.             <?php endforeach; ?>
  233.            
  234.             <?php $output .= '</ul></div>' ?>
  235.  
  236.         <?php endif;
  237.  
  238.  
  239.        
  240.        
  241.  
  242.     wp_reset_postdata();
  243.  
  244.     return !empty($output) ? $output : $default_content;
  245.  
  246. }
  247. add_filter('cspml_before_listing_thumb', 'cspml_change_image', 10, 6);
Advertisement
Add Comment
Please, Sign In to add comment