/** * Output by posts */ public function output_by_posts($grid_preview = false) { global $sitepress; $post_limit = 99999; $base = new Essential_Grid_Base(); $navigation_c = new Essential_Grid_Navigation($this->grid_id); $meta_c = new Essential_Grid_Meta(); $item_skin = new Essential_Grid_Item_Skin(); $item_skin->grid_id = $this->grid_id; $item_skin->set_grid_type($base->getVar($this->grid_params, 'layout', 'even')); $item_skin->set_default_image_by_id($base->getVar($this->grid_postparams, 'default-image', 0, 'i')); $m = new Essential_Grid_Meta(); $skins_html = ''; $skins_css = ''; $filters = array(); $rows_unlimited = $base->getVar($this->grid_params, 'rows-unlimited', 'on'); $load_more = $base->getVar($this->grid_params, 'load-more', 'none'); $load_more_start = $base->getVar($this->grid_params, 'load-more-start', 3, 'i'); if ($rows_unlimited == 'on' && $load_more !== 'none' && $grid_preview == false) { //grid_preview means disable load more in preview $post_limit = $load_more_start; } $start_sortby = $base->getVar($this->grid_params, 'sorting-order-by-start', 'none'); $start_sortby_type = $base->getVar($this->grid_params, 'sorting-order-type', 'ASC'); $post_category = $base->getVar($this->grid_postparams, 'post_category'); $post_types = $base->getVar($this->grid_postparams, 'post_types'); $page_ids = explode(',', $base->getVar($this->grid_postparams, 'selected_pages', '-1')); $cat_relation = $base->getVar($this->grid_postparams, 'category-relation', 'OR'); $max_entries = $this->get_maximum_entries($this); $additional_query = $base->getVar($this->grid_postparams, 'additional-query', ''); if ($additional_query !== '') { $additional_query = wp_parse_args($additional_query); } $cat_tax = array('cats' => '', 'tax' => ''); if ($this->custom_posts !== null) { //output by specific set posts $posts = Essential_Grid_Base::get_posts_by_ids($this->custom_posts, $start_sortby, $start_sortby_type); $cat_tax_obj = Essential_Grid_Base::get_categories_by_posts($posts); if (!empty($cat_tax_obj)) { $cat_tax['cats'] = Essential_Grid_Base::translate_categories_to_string($cat_tax_obj); } //$cat_tax = Essential_Grid_Base::getCatAndTaxData($post_category); //get cats by posts } elseif ($this->custom_special !== null) { //output by some special rule $max_entries = intval($base->getVar($this->grid_params, 'max-entries', '20')); if ($max_entries == 0) { $max_entries = 20; } switch ($this->custom_special) { case 'related': $posts = Essential_Grid_Base::get_related_posts($max_entries); break; case 'popular': $posts = Essential_Grid_Base::get_popular_posts($max_entries); break; case 'latest': default: $posts = Essential_Grid_Base::get_latest_posts($max_entries); break; } $cat_tax_obj = Essential_Grid_Base::get_categories_by_posts($posts); if (!empty($cat_tax_obj)) { $cat_tax['cats'] = Essential_Grid_Base::translate_categories_to_string($cat_tax_obj); } //$cat_tax = Essential_Grid_Base::getCatAndTaxData($post_category); //get cats by posts } else { //output with the grid settings from an existing grid $cat_tax = Essential_Grid_Base::getCatAndTaxData($post_category); $posts = Essential_Grid_Base::getPostsByCategory($this->grid_id, $cat_tax['cats'], $post_types, $cat_tax['tax'], $page_ids, $start_sortby, $start_sortby_type, $max_entries, $additional_query, true, $cat_relation); } $nav_layout = $base->getVar($this->grid_params, 'navigation-layout', array()); $nav_skin = $base->getVar($this->grid_params, 'navigation-skin', 'minimal-light'); $hover_animation = $base->getVar($this->grid_params, 'hover-animation', 'fade'); $filter_allow = $base->getVar($this->grid_params, 'filter-arrows', 'single'); $filter_start = $base->getVar($this->grid_params, 'filter-start', ''); $nav_type = $base->getVar($this->grid_params, 'nagivation-type', 'internal'); $do_nav = $nav_type == 'internal' ? true : false; $order_by = explode(',', $base->getVar($this->grid_params, 'sorting-order-by', 'date')); if (!is_array($order_by)) { $order_by = array($order_by); } $order_by_start = $base->getVar($this->grid_params, 'sorting-order-by-start', 'none'); if (strpos($order_by_start, 'eg-') === 0 || strpos($order_by_start, 'egl-') === 0) { //add meta at the end for meta sorting //if essential Meta, replace to meta name. Else -> replace - and _ with space, set each word uppercase $metas = $m->get_all_meta(); $f = false; if (!empty($metas)) { foreach ($metas as $meta) { if ('eg-' . $meta['handle'] == $order_by_start || 'egl-' . $meta['handle'] == $order_by_start) { $f = true; $order_by_start = $meta['name']; break; } } } if ($f === false) { $order_by_start = ucwords(str_replace(array('-', '_'), array(' ', ' '), $order_by_start)); } } $sort_by_text = $base->getVar($this->grid_params, 'sort-by-text', __('Sort By ', EG_TEXTDOMAIN)); $search_text = $base->getVar($this->grid_params, 'search-text', __('Search...', EG_TEXTDOMAIN)); $module_spacings = $base->getVar($this->grid_params, 'module-spacings', '5'); $top_1_align = $base->getVar($this->grid_params, 'top-1-align', 'center'); $top_2_align = $base->getVar($this->grid_params, 'top-2-align', 'center'); $bottom_1_align = $base->getVar($this->grid_params, 'bottom-1-align', 'center'); $bottom_2_align = $base->getVar($this->grid_params, 'bottom-2-align', 'center'); $top_1_margin = $base->getVar($this->grid_params, 'top-1-margin-bottom', 0, 'i'); $top_2_margin = $base->getVar($this->grid_params, 'top-2-margin-bottom', 0, 'i'); $bottom_1_margin = $base->getVar($this->grid_params, 'bottom-1-margin-top', 0, 'i'); $bottom_2_margin = $base->getVar($this->grid_params, 'bottom-2-margin-top', 0, 'i'); $left_margin = $base->getVar($this->grid_params, 'left-margin-left', 0, 'i'); $right_margin = $base->getVar($this->grid_params, 'right-margin-right', 0, 'i'); $nav_styles['top-1'] = array('margin-bottom' => $top_1_margin . 'px', 'text-align' => $top_1_align); $nav_styles['top-2'] = array('margin-bottom' => $top_2_margin . 'px', 'text-align' => $top_2_align); $nav_styles['left'] = array('margin-left' => $left_margin . 'px'); $nav_styles['right'] = array('margin-right' => $right_margin . 'px'); $nav_styles['bottom-1'] = array('margin-top' => $bottom_1_margin . 'px', 'text-align' => $bottom_1_align); $nav_styles['bottom-2'] = array('margin-top' => $bottom_2_margin . 'px', 'text-align' => $bottom_2_align); $ajax_container_position = $base->getVar($this->grid_params, 'ajax-container-position', 'top'); if ($do_nav) { //only do if internal is selected $navigation_c->set_special_class('esg-fgc-' . $this->grid_id); $filters_meta = array(); foreach ($this->grid_params as $gkey => $gparam) { if (strpos($gkey, 'filter-selected') === false) { continue; } $fil_id = intval(str_replace('filter-selected-', '', $gkey)); $fil_id = $fil_id == 0 ? '' : '-' . $fil_id; $filters_arr = array(); $filters_arr['filter' . $fil_id]['filter-grouping'] = $base->getVar($this->grid_params, 'filter-grouping' . $fil_id, 'false'); $filters_arr['filter' . $fil_id]['filter-listing'] = $base->getVar($this->grid_params, 'filter-listing' . $fil_id, 'list'); $filters_arr['filter' . $fil_id]['filter-selected'] = $base->getVar($this->grid_params, 'filter-selected' . $fil_id, array()); $filter_all_text = $base->getVar($this->grid_params, 'filter-all-text' . $fil_id, __('Filter - All', EG_TEXTDOMAIN)); $filter_dropdown_text = $base->getVar($this->grid_params, 'filter-dropdown-text' . $fil_id, __('Filter Categories', EG_TEXTDOMAIN)); $show_count = $base->getVar($this->grid_params, 'filter-counter' . $fil_id, 'off'); if (!empty($filters_arr['filter' . $fil_id]['filter-selected'])) { if (!empty($posts) && count($posts) > 0) { foreach ($filters_arr['filter' . $fil_id]['filter-selected'] as $fk => $filter) { if (strpos($filter, 'meta-') === 0) { unset($filters_arr['filter' . $fil_id]['filter-selected'][$fk]); //delete entry foreach ($posts as $key => $post) { $fil = str_replace('meta-', '', $filter); $post_filter_meta = $meta_c->get_meta_value_by_handle($post['ID'], 'eg-' . $fil); $arr = json_decode($post_filter_meta, true); $cur_filter = is_array($arr) ? $arr : array($post_filter_meta); //$cur_filter = explode(',', $post_filter_meta); $add_filter = array(); if (!empty($cur_filter)) { foreach ($cur_filter as $k => $v) { if (trim($v) !== '') { $add_filter[sanitize_key($v)] = array('name' => $v, 'slug' => sanitize_key($v), 'parent' => '0'); if (!empty($filters_arr['filter' . $fil_id]['filter-selected'])) { $filter_found = false; foreach ($filters_arr['filter' . $fil_id]['filter-selected'] as $fcheck) { if ($fcheck == sanitize_key($v)) { $filter_found = true; break; } } if (!$filter_found) { $filters_arr['filter' . $fil_id]['filter-selected'][] = sanitize_key($v); //add found meta } } else { $filters_arr['filter' . $fil_id]['filter-selected'][] = sanitize_key($v); //add found meta } } } $filters_meta = $filters_meta + $add_filter; if (!empty($add_filter)) { $navigation_c->set_filter($add_filter); } } } } } } } $navigation_c->set_filter_settings('filter' . $fil_id, $filters_arr['filter' . $fil_id]); $navigation_c->set_filter_text($filter_all_text, $fil_id); $navigation_c->set_dropdown_text($filter_dropdown_text, $fil_id); $navigation_c->set_show_count($show_count, $fil_id); } $navigation_c->set_filter_type($filter_allow); $navigation_c->set_filter_start_select($filter_start); $navigation_c->set_specific_styles($nav_styles); $navigation_c->set_layout($nav_layout); //set the layout $navigation_c->set_orders($order_by); //set order of filter $navigation_c->set_orders_text($sort_by_text); //set order of filter $navigation_c->set_orders_start($order_by_start); //set order of filter $navigation_c->set_search_text($search_text); } $nav_filters = array(); $taxes = array('post_tag'); if (!empty($cat_tax['tax'])) { $taxes = explode(',', $cat_tax['tax']); } if (!empty($cat_tax['cats'])) { $cats = explode(',', $cat_tax['cats']); foreach ($cats as $key => $id) { if (Essential_Grid_Wpml::is_wpml_exists() && isset($sitepress)) { $new_id = icl_object_id($id, 'category', true, $sitepress->get_default_language()); $cat = get_category($new_id); } else { $cat = get_category($id); } if (is_object($cat)) { $nav_filters[$id] = array('name' => $cat->cat_name, 'slug' => sanitize_key($cat->slug), 'parent' => $cat->category_parent); } foreach ($taxes as $custom_tax) { $term = get_term_by('id', $id, $custom_tax); if (is_object($term)) { $nav_filters[$id] = array('name' => $term->name, 'slug' => sanitize_key($term->slug), 'parent' => $term->parent); } } } if (!empty($filters_meta)) { $nav_filters = $filters_meta + $nav_filters; } asort($nav_filters); } $item_skin->init_by_id($base->getVar($this->grid_params, 'entry-skin', 0, 'i')); $lazy_load = $base->getVar($this->grid_params, 'lazy-loading', 'off'); if ($lazy_load == 'on') { $item_skin->set_lazy_load(true); } $default_media_source_order = $base->getVar($this->grid_postparams, 'media-source-order', ''); $item_skin->set_default_media_source_order($default_media_source_order); $default_lightbox_source_order = $base->getVar($this->grid_params, 'lb-source-order', ''); $item_skin->set_default_lightbox_source_order($default_lightbox_source_order); $default_aj_source_order = $base->getVar($this->grid_params, 'aj-source-order', ''); $item_skin->set_default_ajax_source_order($default_aj_source_order); $lightbox_mode = $base->getVar($this->grid_params, 'lightbox-mode', 'single'); $lightbox_include_media = $base->getVar($this->grid_params, 'lightbox-exclude-media', 'off'); $post_media_source_type = $base->getVar($this->grid_postparams, 'image-source-type', 'full'); $default_video_poster_order = $base->getVar($this->grid_params, 'poster-source-order', ''); $item_skin->set_default_video_poster_order($default_video_poster_order); $layout = $base->getVar($this->grid_params, 'layout', 'even'); $layout_sizing = $base->getVar($this->grid_params, 'layout-sizing', 'boxed'); if ($layout_sizing !== 'fullwidth' && $layout == 'masonry') { $item_skin->set_poster_cropping(true); } $found_filter = array(); $i = 1; if ($lightbox_mode == 'content' || $lightbox_mode == 'content-gallery' || $lightbox_mode == 'woocommerce-gallery') { $item_skin->set_lightbox_rel('ess-' . $this->grid_id); } if (!empty($posts) && count($posts) > 0) { foreach ($posts as $key => $post) { if ($grid_preview == false) { //check if post should be visible or if its invisible on current grid settings $is_visible = $this->check_if_visible($post['ID'], $this->grid_id); if ($is_visible == false) { continue; } // continue if invisible } $post_media_source_data = $base->get_post_media_source_data($post['ID'], $post_media_source_type); $post_video_ratios = $m->get_post_video_ratios($post['ID']); $filters = array(); //$categories = get_the_category($post['ID']); $categories = $base->get_custom_taxonomies_by_post_id($post['ID']); //$tags = wp_get_post_terms($post['ID']); $tags = get_the_tags($post['ID']); if (!empty($categories)) { foreach ($categories as $key => $category) { $filters[$category->term_id] = array('name' => $category->name, 'slug' => sanitize_key($category->slug), 'parent' => $category->parent); } } if (!empty($tags)) { foreach ($tags as $key => $taxonomie) { $filters[$taxonomie->term_id] = array('name' => $taxonomie->name, 'slug' => sanitize_key($taxonomie->slug), 'parent' => '0'); } } $filter_meta_selected = $base->getVar($this->grid_params, 'filter-selected', array()); if (!empty($filter_meta_selected)) { foreach ($filter_meta_selected as $filter) { if (strpos($filter, 'meta-') === 0) { $fil = str_replace('meta-', '', $filter); $post_filter_meta = $meta_c->get_meta_value_by_handle($post['ID'], 'eg-' . $fil); $arr = json_decode($post_filter_meta, true); $cur_filter = is_array($arr) ? $arr : array($post_filter_meta); //$cur_filter = explode(',', $post_filter_meta); if (!empty($cur_filter)) { foreach ($cur_filter as $k => $v) { if (trim($v) !== '') { $filters[sanitize_key($v)] = array('name' => $v, 'slug' => sanitize_key($v), 'parent' => '0'); } } } } } } if (is_array($order_by) && !empty($order_by)) { $sort = $this->prepare_sorting_array_by_post($post, $order_by); $item_skin->set_sorting($sort); } $found_filter = $found_filter + $filters; //these are the found filters, only show filter that the posts have //switch to different skin $use_item_skin_id = json_decode(get_post_meta($post['ID'], 'eg_use_skin', true), true); if ($use_item_skin_id !== false && isset($use_item_skin_id[$this->grid_id]['use-skin'])) { $use_item_skin_id = $use_item_skin_id[$this->grid_id]['use-skin']; } else { $use_item_skin_id = -1; } $use_item_skin_id = apply_filters('essgrid_modify_post_item_skin', $use_item_skin_id, $post, $this->grid_id); $item_skin->switch_item_skin($use_item_skin_id); $item_skin->register_layer_css(); $item_skin->register_skin_css(); if ($i > $post_limit) { $this->load_more_post_array[$post['ID']] = $filters; //set for load more, only on elements that will not be loaded from beginning continue; //Load only selected numbers of items at start (for load more) } $i++; if ($lightbox_mode == 'content' || $lightbox_mode == 'content-gallery' || $lightbox_mode == 'woocommerce-gallery') { switch ($lightbox_mode) { case 'content': $lb_add_images = $base->get_all_content_images($post['ID']); break; case 'content-gallery': $lb_add_images = $base->get_all_gallery_images($post['post_content'], true); break; case 'woocommerce-gallery': $lb_add_images = array(); if (Essential_Grid_Woocommerce::is_woo_exists()) { $lb_add_images = Essential_Grid_Woocommerce::get_image_attachements($post['ID'], true); } break; } $item_skin->set_lightbox_addition(array('items' => $lb_add_images, 'base' => $lightbox_include_media)); } $item_skin->set_filter($filters); $item_skin->set_media_sources($post_media_source_data); $item_skin->set_media_sources_type($post_media_source_type); $item_skin->set_video_ratios($post_video_ratios); $item_skin->set_post_values($post); ob_start(); $item_skin->output_item_skin($grid_preview); $skins_html .= ob_get_contents(); ob_clean(); ob_end_clean(); if ($grid_preview == false) { ob_start(); $item_skin->output_element_css_by_meta(); $skins_css .= ob_get_contents(); ob_clean(); ob_end_clean(); } } } else { return false; } $remove_filter = array_diff_key($nav_filters, $found_filter); //check if we have filter that no post has (comes through multilanguage) if (!empty($remove_filter)) { foreach ($remove_filter as $key => $rem) { //we have, so remove them from the filter list before setting the filter list unset($nav_filters[$key]); } } if ($do_nav) { //only do if internal is selected $navigation_c->set_filter($nav_filters); //set filters $nav_filters $found_filter $navigation_c->set_filter_type($filter_allow); $navigation_c->set_filter_start_select($filter_start); } ob_start(); $item_skin->generate_element_css(); $skins_css .= ob_get_contents(); ob_clean(); ob_end_clean(); if ($do_nav) { //only do if internal is selected $found_skin = array(); $navigation_skin = $base->getVar($this->grid_params, 'navigation-skin', 'minimal-light'); $navigation_special_skin = $base->getVar($this->grid_params, 'navigation-special-skin', array()); ob_start(); $navigation_c->output_navigation_skin($navigation_skin); $found_skin[$navigation_skin] = true; if (!empty($navigation_special_skin)) { foreach ($navigation_special_skin as $spec_skin) { if (!isset($found_skin[$spec_skin])) { $navigation_c->output_navigation_skin($spec_skin); $found_skin[$spec_skin] = true; } } } $nav_css = ob_get_contents(); ob_clean(); ob_end_clean(); echo $nav_css; } echo $skins_css; if ($item_skin->ajax_loading == true && $ajax_container_position == 'top') { echo $this->output_ajax_container(); } $this->output_wrapper_pre($grid_preview); if ($do_nav) { //only do if internal is selected $navigation_c->output_layout('top-1', $module_spacings); $navigation_c->output_layout('top-2', $module_spacings); } $this->output_grid_pre(); echo $skins_html; $this->output_grid_post(); if ($do_nav) { //only do if internal is selected $navigation_c->output_layout('bottom-1', $module_spacings); $navigation_c->output_layout('bottom-2', $module_spacings); $navigation_c->output_layout('left'); $navigation_c->output_layout('right'); //check if search was added. If yes, we also need to add the "Filter All" filter if not existing $navigation_c->check_for_search(); } $this->output_wrapper_post(); if ($item_skin->ajax_loading == true && $ajax_container_position == 'bottom') { echo $this->output_ajax_container(); } $load_lightbox = $item_skin->do_lightbox_loading(); if (!$grid_preview) { $this->output_grid_javascript($load_lightbox); } }