#----------------------------------------------------------------- # Portfoliio page #----------------------------------------------------------------- // Get the data and template for a portfolio page //................................................................ if ( ! function_exists( 'make_theme_portfolio_page' ) ) : function make_theme_portfolio_page($settings = false) { global $portfolio_query, $shortcode_values, $paged; $shortcode_values = $settings; $portfolio = array(); if ($settings && is_array($settings)) { $portfolio = $settings; // Unique ID. Used to identify multiple portfolios on one page. $id = base_convert(microtime(), 10, 36); // a random id generated for each form. $shortcode_values['id'] = $id; // set some defaults in the shortcode values //................................................................ // columns if (!$shortcode_values['columns']) { $shortcode_values['columns'] = 3; // default } // paging if (!$portfolio['paging']) { $shortcode_values['paging'] = true; // default is to use paging } else { $sc_val = strtolower(trim($portfolio['paging'])); if ($sc_val == 'no' || $sc_val == 'n' || $sc_val == '0' || $sc_val == 'false' || $sc_val == 'hide' || $sc_val == 'off' ) { $shortcode_values['paging'] = false; } } // posts per page if (!$portfolio['posts_per_page']) { $portfolio['posts_per_page'] = floor((int) $shortcode_values['columns'] * 2); } // check a few query values that need preperation //................................................................ // the categories to include (converted to array) if ($portfolio['category']) { $cats = explode(',', $settings['category']); foreach ((array) $cats as $cat) : $portfolio['category__in'][] = trim($cat); endforeach; unset($portfolio['category']); // not a query variable so we remove it } // the post/page ID's to include (converted to array) if ($portfolio['page_id']) { $page_id = explode(',', $settings['page_id']); foreach ((array) $page_id as $id) : $portfolio['post__in'][] = trim($id); endforeach; unset($portfolio['page_id']); // not a query variable so we remove it } // set orderby to "menu_order" for pages, if not specified by user (otherwise it will use the published date) if ($portfolio['post_type'] == 'page' && !$portfolio['orderby'] ) { $portfolio['orderby'] = 'menu_order'; if (!$portfolio['order']) $portfolio['order'] = 'ASC'; } // not a query variables so we remove them unset($portfolio['columns']); unset($portfolio['excerpt']); unset($portfolio['excerpt_length']); unset($portfolio['title']); unset($portfolio['link']); unset($portfolio['image_ratio']); unset($portfolio['content_width']); unset($portfolio['paging']); // for pagination to work... if ($shortcode_values['paging']) { // if turned off we don't want this variable set or it will be populated by other shortcodes $portfolio['paged'] = $paged; } // create query the portfolio (pass it to $wp_query) $portfolio_query = new WP_Query( $portfolio ); // turn on output buffering to capture script output ob_start(); get_template_part( 'template', 'portfolio' ); // get the content that has been output $content = ob_get_clean(); wp_reset_query(); // return the content return $content; } } endif;