/** * Displaying the widget * * Handle the display of the widget * @param array * @param array */ function widget($args, $instance) { extract($args); global $wp_query; /* Before widget(defined by theme)*/ echo $before_widget; $query = array(); if (!empty($instance['number_of_posts'])) { $query['showposts'] = $instance['number_of_posts']; } else { $query['showposts'] = 1; } $formats = get_post_format_slugs(); foreach ((array) $formats as $i => $format) { $formats[$i] = 'post-format-' . $format; } $query['tax_query'] = array(array('taxonomy' => 'post_format', 'field' => 'slug', 'terms' => $formats, 'operator' => 'NOT IN')); /* START Widget body */ //if ( isset( $instance['title'] ) ) echo $before_title . $instance['title'] . $after_title; if (!empty($instance['title'])) { echo $before_title; echo do_shortcode($instance['title']); echo $after_title; } $i = 1; $num_posts = sizeof(query_posts($query)); if (have_posts()) { ?> <div class="postitems-wrapper"> <?php while (have_posts()) { the_post(); if (!empty($instance['excerpt_length'])) { if (function_exists('iconv')) { $text = iconv_substr(strip_tags(get_the_content()), 0, $instance['excerpt_length'], 'UTF-8'); } else { $text = substr(strip_tags(get_the_content()), 0, $instance['excerpt_length']); } } else { $text = get_the_excerpt(); } $thumbnail_id = get_post_thumbnail_id(get_the_ID()); $thumbnail_args = wp_get_attachment_image_src($thumbnail_id, 'single-post-thumbnail'); switch ($instance['thumbnail_position']) { case 'left': $thumbnail_class = 'fl'; break; case 'right': $thumbnail_class = 'fr'; break; default: $thumbnail_class = ''; break; } $post_class = ''; // Is last post if ($i == $num_posts) { $post_class = ' last'; } // Has thumbnail if (has_post_thumbnail(get_the_ID()) && $instance['show_thumbnails']) { $post_class .= ' with-thumbnail'; } ?> <div class="postitem clearfix <?php echo $post_class; ?> "> <?php if (has_post_thumbnail(get_the_ID()) && $instance['show_thumbnails']) { ?> <div class="thumb-wrap <?php echo $thumbnail_class; ?> "> <a href="<?php the_permalink(); ?> " class="greyscale"> <?php if (TIMTHUMB_URL != '') { ?> <img class="thumb" src="<?php echo TIMTHUMB_URL; ?> ?src=<?php echo getRealThumbnailUrl($thumbnail_args['0']); ?> &w=<?php echo $instance['thumbnail_width']; ?> &h=<?php echo $instance['thumbnail_height']; ?> " alt="" /> <?php } else { ?> <img class="thumb" src="<?php echo AitImageResizer::resize($thumbnail_args['0'], array('w' => $instance['thumbnail_width'], 'h' => $instance['thumbnail_height'])); ?> " alt="" /> <?php } ?> </a> </div><!-- /.thumb-wrap --> <?php } ?> <h3><a href="<?php the_permalink(); ?> "><?php the_title_attribute(); ?> </a></h3> <p><small><?php echo $text; ?> </small></p> <?php if (!empty($instance['show_read_more'])) { ?> <div class="read-more"> <small class="fl"> <strong><?php echo get_the_date(); ?> </strong> </small> <small class="fr"> <a href="<?php the_permalink(); ?> "><?php echo __('read more', 'ait'); ?> </a> </small> </div> <?php } ?> </div><!-- /.item --> <?php $i++; } ?> </div><?php } else { ?> <div class="postitems-wrapper"> <?php echo __('<div class="no-content">No posts</div>'); ?> </div> <?php } /* After widget(defined by theme)*/ echo $after_widget; wp_reset_query(); }
if ($latteParams['type']) { // show all items on map if (isset($aitThemeOptions->search->searchShowMap)) { $radius = array(); if (isset($_GET['geo'])) { $radius[] = $_GET['geo-radius']; $radius[] = $_GET['geo-lat']; $radius[] = $_GET['geo-lng']; } $latteParams['items'] = getItems(intval($_GET['categories']), intval($_GET['locations']), $GLOBALS['wp_query']->query_vars['s'], $radius); } $posts = $wp_query->posts; foreach ($posts as $item) { $item->link = get_permalink($item->ID); $image = wp_get_attachment_image_src(get_post_thumbnail_id($item->ID)); if ($image !== false) { $item->thumbnailDir = getRealThumbnailUrl($image[0]); } else { $item->thumbnailDir = getRealThumbnailUrl($GLOBALS['aitThemeOptions']->directory->defaultItemImage); } $item->optionsDir = get_post_meta($item->ID, '_ait-dir-item', true); $item->excerptDir = aitGetPostExcerpt($item->post_excerpt, $item->post_content); $item->packageClass = getItemPackageClass($item->post_author); $item->rating = get_post_meta($item->ID, 'rating', true); } $latteParams['posts'] = $posts; } else { $latteParams['archive'] = new WpLatteArchiveEntity(); $latteParams['posts'] = WpLatte::createPostEntity($wp_query->posts); } WPLatte::createTemplate(basename(__FILE__, '.php'), $latteParams)->render();
$termMarker = $GLOBALS['aitThemeOptions']->directoryMap->defaultMapMarkerImage; if (isset($terms[0])) { $termMarker = getCategoryMeta("marker", intval($terms[0]->term_id)); } $item->marker = $termMarker; // excerpt $item->excerptDir = aitGetPostExcerpt($item->post_excerpt, $item->post_content); $item->packageClass = getItemPackageClass($item->post_author); $latteParams['term'] = null; $latteParams['items'] = array($item); $latteParams['ancestors'] = array(); } else { if (isset($terms[0])) { // term $terms[0]->link = get_term_link(intval($terms[0]->term_id), 'ait-dir-item-category'); $terms[0]->icon = getRealThumbnailUrl(getCategoryMeta("icon", intval($terms[0]->term_id))); $terms[0]->marker = getCategoryMeta("marker", intval($terms[0]->term_id)); $termAncestors = array_reverse(get_ancestors(intval($terms[0]->term_id), 'ait-dir-item-category')); $ancestors = array(); foreach ($termAncestors as $anc) { $term = get_term($anc, 'ait-dir-item-category'); $term->link = get_term_link(intval($term->term_id), 'ait-dir-item-category'); $ancestors[] = $term; } $categoryID = intval($terms[0]->term_id); $location = 0; $search = ''; $radiusKm = $aitThemeOptions->directory->showDistanceInDetail ? $aitThemeOptions->directory->showDistanceInDetail : 1000; // center and radius $radius = array($radiusKm, $latteParams['options']['gpsLatitude'], $latteParams['options']['gpsLongitude']); $items = getItems($categoryID, $location, $search, $radius);
} else { $item->thumbnailDir = getRealThumbnailUrl($aitThemeOptions->directory->defaultItemImage); } $item->marker = $term->marker; $item->optionsDir = get_post_meta($item->ID, '_ait-dir-item', true); $item->packageClass = getItemPackageClass($item->post_author); $item->rating = get_post_meta($item->ID, 'rating', true); } // add posts details foreach ($posts as $item) { $item->link = get_permalink($item->id); $image = wp_get_attachment_image_src(get_post_thumbnail_id($item->id)); if ($image !== false) { $item->thumbnailDir = getRealThumbnailUrl($image[0]); } else { $item->thumbnailDir = getRealThumbnailUrl($aitThemeOptions->directory->defaultItemImage); } $item->optionsDir = get_post_meta($item->id, '_ait-dir-item', true); //$item->excerptDir = aitGetPostExcerpt($item->excerpt,$item->content); $item->packageClass = getItemPackageClass($item->author->id); $item->rating = get_post_meta($item->id, 'rating', true); } // breadcrumbs $ancestorsIDs = array_reverse(get_ancestors(intval($term->term_id), 'ait-dir-item-category')); $ancestors = array(); foreach ($ancestorsIDs as $anc) { $cat = get_term($anc, 'ait-dir-item-category'); $cat->link = get_term_link($anc, 'ait-dir-item-category'); $ancestors[] = $cat; } $latteParams['ancestors'] = $ancestors;
$latteParams['post'] = WpLatte::createPostEntity($GLOBALS['wp_query']->post, array('meta' => $GLOBALS['pageOptions'])); // get top categories $subcategories = array(); if (isset($aitThemeOptions->directory->showTopCategories)) { //$catNumber = ($aitThemeOptions->directory->topCategoriesNumber) ? $aitThemeOptions->directory->topCategoriesNumber : 9; $subcategories = get_terms('ait-dir-item-category', array('number' => 999999999, 'hide_empty' => false, 'parent' => 0)); // add category links foreach ($subcategories as $category) { $category->link = get_term_link(intval($category->term_id), 'ait-dir-item-category'); $category->icon = getRealThumbnailUrl(getCategoryMeta("icon", intval($category->term_id))); $category->excerpt = getCategoryMeta("excerpt", intval($category->term_id)); } } $latteParams['subcategories'] = $subcategories; // get top locations $sublocations = array(); if (isset($aitThemeOptions->directory->showTopLocations)) { $sublocations = get_terms('ait-dir-item-location', array('number' => 999999999, 'hide_empty' => false, 'parent' => 0)); // add category links foreach ($sublocations as $location) { $location->link = get_term_link(intval($location->term_id), 'ait-dir-item-location'); $location->icon = getRealThumbnailUrl(getLocationMeta("icon", intval($location->term_id))); $location->excerpt = getlocationMeta("excerpt", intval($location->term_id)); } } $latteParams['sublocations'] = $sublocations; $latteParams['sidebarType'] = 'home'; /** * Fire! */ WPLatte::createTemplate(basename(__FILE__, '.php'), $latteParams)->render();