La Hita Alquiler de Maquinaria Design Archivos - La Hita Alquiler de Maquinaria

WORK

From Our Company
/** * Utility singleton class * This class is for all the function that can be * used outside any of the portfolio classes hiearchy * * @author jason.xie@victheme.com * */ class VTCore_Portfolio_Utility extends VTCore_Utility { /** * Altering main query for condition when user is trying to * view custom template when on single page */ public static function buildPortfolioPost($args = array()) { $config = new VTCore_Portfolio_Config(); $defaults = array( 'post_type' => 'portfolio', 'posts_per_page' => $config->getOption('grid', 'pagination'), 'post_status' => 'publish', 'paged' => isset($_GET['paged_portfolio']) ? $_GET['paged_portfolio'] : 1, ); $args = VTCore_Utility::arrayMergeRecursiveDistinct($args, $defaults); return new WP_Query($args); } /** * Wrapper for themer to retrieve configuration value easily */ public static function getOption($type, $subkey = false, $value = false) { $config = new VTCore_Portfolio_Config(); return $config->getOption($type, $subkey, $value); } /** * Helper function for extract and building taxonomy links */ public static function buildTaxonomyLink($post) { $terms = get_object_term_cache($post->ID, 'portfolio_category'); $links = array(); if (is_array($terms)) { foreach ( $terms as $term ) { $links[] = '' . $term->name . ''; } } return implode(', ', $links); } /** * Extracting taxonomy from posts * * The return array is compatible with buildChildrenTaxonomy() method. */ public static function buildTaxonomy($posts, $top_level = false) { $taxonomies = array(); foreach ($posts as $data) { if (!isset($check[$data->post_type])) { $check[$data->post_type] = true; $object = get_object_taxonomies($data->post_type); $taxonomies += $object; } } if (isset($check['post'])) { $taxonomies[] = 'category'; } $terms = array(); foreach ($taxonomies as $taxonomy_name) { foreach (get_terms($taxonomy_name) as $term) { if ($term->parent != 0 && $top_level) { continue; } $terms[$term->term_id] = $term; }; } return $terms; } /** * Retrieving children taxonomy of current parent taxonomy * Only applicable for retrieving portfolio category taxonomies * * The return array is compatible with buildTaxonomy() method. */ public static function buildChildrenTaxonomy($parent_id) { if (!is_numeric($parent_id)) { $parentObject = get_term_by('slug', $parent_id, 'portfolio_category'); $parent_id = $parentObject->term_id; } $childterms = get_term_children($parent_id, 'portfolio_category'); $terms = array(); foreach ($childterms as $childid) { $terms[$childid] = get_term_by('term_id', $childid, 'portfolio_category'); } return $terms; } /** * Retrieving parent taxonomy of a given children * The return array is compatible with buildTaxonomy() method. */ public static function buildParentTaxonomy($child_id) { if (!is_numeric($child_id)) { $childObject = get_term_by('slug', $child_id, 'portfolio_category'); $child_id = $childObject->term_id; } $parent_id = wp_get_term_taxonomy_parent_id($child_id, 'portfolio_category'); $terms = array( $child_id => get_term_by('term_id', $parent_id, 'portfolio_category'), ); return $parent_id == false ? array() : $terms; } /** * Build list of taxonomy slugs from post object */ public static function buildSlug($post) { $type = $post->post_type; if ($type != 'post') { $taxonomies = get_object_taxonomies($type); } else { $taxonomies = array('category'); } $slug = array(); foreach ($taxonomies as $taxonomy) { foreach (wp_get_post_terms($post->ID, $taxonomy) as $term) { $slug[] = $term->slug; } } return $slug; } /** * Building the portfolio post meta for teaser */ public static function processThumbnail($post, $meta, $size = 'portfolio-thumbnail') { $image = ''; // Get the media thumbnail if (!empty($meta['media']['thumbnail'])) { $image = wp_get_attachment_image($meta['media']['thumbnail'], $size); } // Fallback to first portfolio image if (empty($image) && isset($meta['media']['contents'][0]['image']) && !empty($meta['media']['contents'][0]['image'])) { $image = wp_get_attachment_image($meta['media']['contents'][0]['image'], $size); } // Fallback to thumbnails if (empty($image)) { $image = get_the_post_thumbnail($post->ID, $size); } return $image; } /** * Filtering out posts by its taxonomy slug. */ public static function getPostBySlug($posts, $slug) { $filtered = array(); foreach ($posts as $post) { $postslugs = self::buildSlug($post); if (in_array($slug, $postslugs)) { $filtered[$post->ID] = $post; } } return $filtered; } /** * Check if we are on portfolio related page * @return boolean */ static public function isPortfolio() { global $wp_query; return (isset($wp_query->is_portfolio) || $wp_query->get('post_type') == 'portfolio' || $wp_query->query_vars['pagename'] == 'portfolio') ? true : false; } }