/** * Returns the content of the column shortcode. * * @since 1.0.0 * @access public * @param array $atts The user-inputted arguments. * @param string $content The content to wrap in a shortcode. * @return string */ public function do_shortcode($atts) { /* Set up the default arguments. */ $defaults = apply_filters('ao_content_upgrades_archive_defaults', array('order' => 'DESC', 'orderby' => 'menu_order', 'count' => 20, 'include' => '', 'exclude' => '', 'before' => '', 'after' => '', 'type' => '')); $args = shortcode_atts($defaults, $atts); $args = apply_filters('ao_content_upgrades_archive_args', $args); $loop_args = array('post_type' => self::$postTypeName, 'order' => $args['order'], 'orderby' => $args['orderby'], 'posts_per_page' => empty($args['count']) ? 20 : $args['count']); if (!empty($args['include'])) { $loop_args['post__in'] = array($args['include']); } elseif (!empty($args['exclude'])) { $loop_args['post__not_in'] = array($args['exclude']); } $data = array(); $data['args'] = $args; $data['loop'] = new WP_Query($loop_args); $templates = array(); if (!empty($args['type'])) { $templates[] = "shortcodes/archive-{$args['type']}.php"; } $templates[] = 'shortcodes/archive.php'; $output = $args['before']; ob_start(); $template = aocu_archive_locate_template($templates); aocu_archive_load_template($template, $data); $output .= ob_get_clean(); $output .= $args['after']; return $output; }
/** * Load a template file. * * @since 1.0.0 * * @param string|array $template_file Absolute path to a file or list of template parts. * @param array $data Optional. List of variables to extract into the template scope. * @param bool $locate Optional. Whether the $template_file argument should be located. Default false. * @param bool $require_once Optional. Whether to require_once or require. Default false. */ function aocu_archive_load_template($template_file, $data = array(), $locate = false, $require_once = false) { if (is_array($data) && !empty($data)) { extract($data, EXTR_SKIP); unset($data); } // Locate the template file specified as the first parameter. if ($locate) { $template_file = aocu_archive_locate_template($template_file); } if ($require_once) { require_once $template_file; } else { require $template_file; } }