/** * Portfolio Loop * @param array $wp_query * @param array $atts * @return output */ function rt_portfolio_post_loop($wp_query = array(), $atts = array()) { global $rt_portfolio_post_values, $rt_portfolio_list_atts; //sanitize fields $atts["id"] = isset($atts["id"]) ? sanitize_html_class($atts["id"]) : 'portfolio-dynamicID-' . rand(100000, 1000000); //defaults $rt_portfolio_list_atts = shortcode_atts(array("id" => 'portfolio-dynamicID-' . rand(100000, 1000000), "list_layout" => get_theme_mod(RT_THEMESLUG . '_portfolio_layout'), "layout_style" => get_theme_mod(RT_THEMESLUG . '_portfolio_layout_style'), "item_style" => get_theme_mod(RT_THEMESLUG . '_portfolio_item_style'), "filterable" => "false", "pagination" => "true", "ajax_pagination" => "false", "featured_image_resize" => get_theme_mod(RT_THEMESLUG . "_portfolio_image_resize"), "featured_image_max_width" => get_theme_mod(RT_THEMESLUG . "_portfolio_image_width"), "featured_image_max_height" => get_theme_mod(RT_THEMESLUG . "_portfolio_image_height"), "featured_image_crop" => get_theme_mod(RT_THEMESLUG . "_portfolio_image_crop"), "list_orderby" => "date", "list_order" => "DESC", "item_per_page" => 10, "categories" => "", "ajax" => "false", "ids" => "", "paged" => 0, "wpml_lang" => ""), $atts); extract($rt_portfolio_list_atts); $wp_reset_postdata = false; //counter $counter = 1; //custom query if (!$wp_query) { //paged if ($pagination && $paged == 0) { if (get_query_var('paged')) { $paged = get_query_var('paged'); } elseif (get_query_var('page')) { $paged = get_query_var('page'); } else { $paged = 1; } } //create a post status array $post_status = is_user_logged_in() ? array('private', 'publish') : "publish"; //general query $args = array('post_status' => $post_status, 'post_type' => 'portfolio', 'orderby' => $list_orderby, 'order' => $list_order, 'posts_per_page' => $item_per_page, 'paged' => $paged); if (!empty($ids)) { $ids = !empty($ids) ? explode(",", trim($ids)) : array(); $args = array_merge($args, array('post__in' => $ids)); } if (!empty($categories)) { $categories = is_array($categories) ? $categories : explode(",", rt_wpml_lang_object_ids($categories, "portfolio_categories", $wpml_lang)); $args = array_merge($args, array('tax_query' => array(array('taxonomy' => 'portfolio_categories', 'field' => 'id', 'terms' => $categories, 'operator' => "IN")))); } $wp_query = new WP_Query($args); //filter navigation if ($filterable !== "false") { //categories - turn into an array $sortCategories = $categories; $sortNavigation = ""; if (!empty($sortCategories)) { if (is_array($sortCategories)) { foreach ($sortCategories as $arrayorder => $termID) { $sortCategories = get_term_by('id', $termID, 'portfolio_categories'); $sortNavigation .= '<li><a href="#" data-filter=".' . $sortCategories->slug . '">' . $sortCategories->name . '</a></li>'; } } } else { $sortCategories = get_terms('portfolio_categories', 'orderby=name&hide_empty=1&order=ASC'); $sortCategories = is_array($sortCategories) ? $sortCategories : ""; foreach ($sortCategories as $key => $term) { $sortNavigation .= '<li><a data-filter=".' . $term->slug . '" title="' . $term->name . '">' . $term->name . '</a></li>'; } } $filter_holder = !empty($sortNavigation) ? sprintf(' <div class="filter-holder" data-list-id="%s"> <ul class="filter_navigation">%s %s</ul> </div>', $id, '<li><a href="#" data-filter="*" class="active animate" title="' . apply_filters("filter_nav_text", __("Show All", "rt_theme")) . '"><span class="icon-filter"></span></a></li>', $sortNavigation) : ""; echo $filter_holder; } $wp_reset_postdata = true; } //get page & post counts $post_count = $wp_query->post_count; $page_count = $wp_query->max_num_pages; //item width percentage $list_layout = !empty($list_layout) ? $list_layout : "1/3"; //layout style $add_holder_class = $list_layout == "1/1" ? "" : ($layout_style == "grid" ? " border_grid fixed_heights" : " masonry"); $add_holder_class .= $filterable !== "false" ? " filterable" : ""; //column class $add_column_class = rt_column_class($list_layout); $add_column_class .= $layout_style == "masonry" ? " isotope-item" : ""; //row count $column_count = rt_column_count($list_layout); if ($wp_query->have_posts()) { //open the wrapper echo "\n" . '<div id="' . $id . '" class="portfolio_list clearfix ' . $add_holder_class . '" data-column-width="' . $column_count . '">' . "\n"; //the loop while ($wp_query->have_posts()) { $wp_query->the_post(); //get post values $rt_portfolio_post_values = rt_get_portfolio_loop_post_values($wp_query->post, $rt_portfolio_list_atts); //selected term list of each post $term_list = get_the_terms($wp_query->post->ID, 'portfolio_categories'); //add terms as class name $addTermsClass = ""; if ($term_list) { if (is_array($term_list)) { foreach ($term_list as $termSlug) { $addTermsClass .= " " . $termSlug->slug; } } } //open row block if ($layout_style != "masonry" && $list_layout != "1/1" && ($counter % $column_count == 1 || $column_count == 1)) { echo '<div class="row clearfix">' . "\n"; } echo $list_layout != "1/1" ? '<div class="col ' . $add_column_class . ' ' . $addTermsClass . '">' . "\n" : ""; get_template_part('portfolio-contents/loop', 'content'); echo $list_layout != "1/1" ? '</div>' . "\n" : ""; //close row block if ($layout_style != "masonry" && $list_layout != "1/1" && ($counter % $column_count == 0 || $post_count == $counter)) { echo '</div>' . "\n"; } $counter++; } //close wrapper echo '</div>' . "\n"; if ($pagination !== "false" && $ajax_pagination === "false" || $pagination !== "false" && $layout_style != "masonry") { rt_get_pagination($wp_query); } if ($ajax_pagination !== "false" && $layout_style == "masonry" && $page_count > 1 && $ajax === "false") { $rt_portfolio_list_atts["purpose"] = "portfolio"; rt_get_ajax_loader_button($rt_portfolio_list_atts, $page_count); } } //reset post data for the new query if ($wp_reset_postdata) { wp_reset_postdata(); } }
/** * Portfolio Carousel * returns html ouput of portfolio custom post type for carousel * * @param array $atts * @return output */ function rt_portfolio_carousel($atts = array()) { global $rt_portfolio_post_values, $rt_portfolio_list_atts, $wpml_lang; //sanitize fields $atts["id"] = isset($atts["id"]) ? sanitize_html_class($atts["id"]) : 'portfolio-dynamicID-' . rand(100000, 1000000); //defaults $rt_portfolio_list_atts = shortcode_atts(array("id" => 'portfolio-dynamicID-' . rand(100000, 1000000), "list_layout" => "1/3", "nav" => "true", "dots" => "false", "featured_image_resize" => "true", "featured_image_max_width" => 0, "featured_image_max_height" => 0, "featured_image_crop" => "false", "item_style" => "style-1", "list_orderby" => "date", "list_order" => "DESC", "max_item" => 10, "categories" => "", "ids" => "", "autoplay" => "false", "timeout" => 5000), $atts); extract($rt_portfolio_list_atts); //counter $counter = 1; //create a post status array $post_status = is_user_logged_in() ? array('private', 'publish') : "publish"; //general query $args = array('post_status' => $post_status, 'post_type' => 'portfolio', 'orderby' => $list_orderby, 'order' => $list_order, 'showposts' => $max_item); if (!empty($ids)) { $ids = !empty($ids) ? explode(",", trim($ids)) : array(); $args = array_merge($args, array('post__in' => $ids)); } if (!empty($categories)) { $categories = is_array($categories) ? $categories : explode(",", rt_wpml_lang_object_ids($categories, "portfolio_categories", $wpml_lang)); $args = array_merge($args, array('tax_query' => array(array('taxonomy' => 'portfolio_categories', 'field' => 'id', 'terms' => $categories, 'operator' => "IN")))); } $wp_query = new WP_Query($args); //column count $item_width = rt_column_count($list_layout); //column class $add_column_class = "item portfolio"; if ($wp_query->have_posts()) { $output = array(); //the loop while ($wp_query->have_posts()) { $wp_query->the_post(); //get post values $rt_portfolio_post_values = rt_get_portfolio_loop_post_values($wp_query->post, $rt_portfolio_list_atts, "carousel"); //selected term list of each post $term_list = get_the_terms($wp_query->post->ID, 'portfolio_categories'); //add terms as class name $addTermsClass = ""; if ($term_list) { if (is_array($term_list)) { foreach ($term_list as $termSlug) { $addTermsClass .= " " . $termSlug->slug; } } } ob_start(); echo '<div class="' . $add_column_class . ' ' . $addTermsClass . '">' . "\n"; get_template_part('portfolio-contents/carousel', 'content'); echo '</div>' . "\n"; $output[] .= ob_get_contents(); ob_end_clean(); $counter++; } //reset post data for the new query wp_reset_postdata(); //carousel atts $atts = array("id" => sanitize_html_class($id), "item_width" => $item_width, "class" => "portfolio-carousel", "nav" => $nav, "dots" => $dots, "autoplay" => $autoplay, "timeout" => $timeout); //create carousel return rt_create_carousel($output, $atts); } }