Exemple #1
0
 function shortcode_locations($atts, $content = null)
 {
     $variables = array('parent' => '', 'column' => 5, 'image_size' => 'thumbnail');
     // image_size = array( 'thumbnail', 'medium', 'large', 'full' )
     extract(shortcode_atts($variables, $atts));
     if (empty($parent)) {
         $parent = 0;
     }
     if (!is_numeric($column)) {
         $column = 5;
     }
     $child_terms = array();
     if (is_numeric($parent)) {
         $child_terms = get_terms('location', array('parent' => $parent, 'hide_empty' => 0));
     } else {
         $parent_obj = get_term_by('name', $parent, 'location');
         if ($parent_id) {
             $child_terms = get_terms('location', array('parent' => $parent_obj->term_id, 'hide_empty' => 0));
         }
     }
     $result = '';
     $result .= '<div class="image-box style9 column-' . esc_attr($column) . '">';
     if (!empty($child_terms) && !is_wp_error($child_terms)) {
         foreach ($child_terms as $child_term) {
             $img_src = get_tax_meta($child_term->term_id, 'lc_image');
             $img = '';
             if (is_array($img_src) && isset($img_src['id'])) {
                 $img = wp_get_attachment_image($img_src['id'], $image_size);
             } else {
                 $img = '<img src="' . TRAV_IMAGE_URL . '/blank.jpg" alt="blank-img">';
             }
             $count = trav_count_posts_in_taxonomy($child_term->term_id, 'location');
             $result .= '<article class="box">';
             $result .= '<figure><a href="' . esc_url(get_term_link($child_term, 'location')) . '" title="' . esc_attr($child_term->name) . '" class="hover-effect yellow">' . $img . '</a></figure>';
             $result .= '<div class="details"><h4 class="box-title">' . $child_term->name . '<small>' . sprintf(__('%d Activities', 'trav'), $count) . '</small></h4>';
             $result .= '<a href="' . esc_url(get_term_link($child_term, 'location')) . '" title="" class="button">' . __('SEE ALL', 'trav') . '</a></div></article>';
         }
     }
     $result .= '</div>';
     return $result;
 }
Exemple #2
0
 function trav_count_posts_in_taxonomy($term_id, $taxonomy)
 {
     $term_obj = get_term($term_id, $taxonomy);
     $count = $term_obj->count;
     $child_terms = get_terms($taxonomy, array('parent' => $term_id));
     if (!empty($child_terms) && !is_wp_error($child_terms)) {
         foreach ($child_terms as $child_term) {
             $count += trav_count_posts_in_taxonomy($child_term->term_id, $taxonomy);
         }
     }
     return $count;
 }