/** * downloads function. * * @access public * @param mixed $atts * @return void */ public function downloads($atts) { global $download_monitor; extract(shortcode_atts(array('per_page' => '-1', 'orderby' => 'title', 'order' => 'desc', 'include' => '', 'exclude' => '', 'offset' => '', 'category' => '', 'category_include_children' => true, 'tag' => '', 'featured' => false, 'members_only' => false, 'template' => dlm_get_default_download_template(), 'loop_start' => '<ul class="dlm-downloads">', 'loop_end' => '</ul>', 'before' => '<li>', 'after' => '</li>'), $atts)); $post__in = !empty($include) ? explode(',', $include) : ''; $post__not_in = !empty($exclude) ? explode(',', $exclude) : ''; $order = strtoupper($order); $meta_key = ''; switch ($orderby) { case 'title': case 'rand': case 'ID': case 'date': case 'modified': case 'post__in': $orderby = $orderby; break; case 'id': $orderby = 'ID'; break; case 'hits': case 'count': case 'download_count': $orderby = 'meta_value'; $meta_key = '_download_count'; break; default: $orderby = 'title'; break; } $args = array('post_type' => 'dlm_download', 'posts_per_page' => $per_page, 'offset' => $offset, 'no_found_rows' => 1, 'post_status' => 'publish', 'orderby' => $orderby, 'order' => $order, '$meta_key' => $meta_key, 'post__in' => $post__in, 'post__not_in' => $post__not_in, 'meta_query' => array()); if ($category || $tag) { $args['tax_query'] = array('relation' => 'AND'); $categories = array_filter(explode(',', $category)); $tags = array_filter(explode(',', $tag)); if (!empty($categories)) { $args['tax_query'][] = array('taxonomy' => 'dlm_download_category', 'field' => 'slug', 'terms' => $categories, 'include_children' => $category_include_children); } if (!empty($tags)) { $args['tax_query'][] = array('taxonomy' => 'dlm_download_tag', 'field' => 'slug', 'terms' => $tags); } } if ($featured === 'true' || $featured === true) { $args['meta_query'][] = array('key' => '_featured', 'value' => 'yes'); } if ($members_only === 'true' || $members_only === true) { $args['meta_query'][] = array('key' => '_members_only', 'value' => 'yes'); } ob_start(); $downloads = new WP_Query($args); if ($downloads->have_posts()) { ?> <?php echo html_entity_decode($loop_start); ?> <?php while ($downloads->have_posts()) { $downloads->the_post(); ?> <?php echo html_entity_decode($before); ?> <?php $download_monitor->get_template_part('content-download', $template); ?> <?php echo html_entity_decode($after); ?> <?php } // end of the loop. ?> <?php echo html_entity_decode($loop_end); ?> <?php } wp_reset_postdata(); return ob_get_clean(); }
/** * downloads function. * * @access public * * @param mixed $atts * * @return void */ public function downloads($atts) { global $dlm_max_num_pages; extract(shortcode_atts(array('per_page' => '-1', 'orderby' => 'date', 'order' => 'desc', 'include' => '', 'exclude' => '', 'offset' => '', 'category' => '', 'category_include_children' => true, 'tag' => '', 'featured' => false, 'members_only' => false, 'template' => dlm_get_default_download_template(), 'loop_start' => '<ul class="dlm-downloads">', 'loop_end' => '</ul>', 'before' => '<li>', 'after' => '</li>', 'paginate' => false), $atts)); $post__in = !empty($include) ? explode(',', $include) : ''; $post__not_in = !empty($exclude) ? explode(',', $exclude) : ''; $order = strtoupper($order); $meta_key = ''; switch ($orderby) { case 'title': case 'rand': case 'ID': case 'date': case 'modified': case 'post__in': $orderby = $orderby; break; case 'id': $orderby = 'ID'; break; case 'hits': case 'count': case 'download_count': $orderby = 'meta_value_num'; $meta_key = '_download_count'; break; default: $orderby = 'title'; break; } $args = array('post_type' => 'dlm_download', 'posts_per_page' => $per_page, 'offset' => $paginate ? (max(1, get_query_var('paged')) - 1) * $per_page : $offset, 'post_status' => 'publish', 'orderby' => $orderby, 'order' => $order, 'meta_key' => $meta_key, 'post__in' => $post__in, 'post__not_in' => $post__not_in, 'meta_query' => array()); if ($category || $tag) { $args['tax_query'] = array('relation' => 'AND'); $tags = array_filter(explode(',', $tag)); // check if we include category children $include_children = $category_include_children === 'true' || $category_include_children === true; if (!empty($category)) { if (preg_match('/\\+/', $category)) { // categories with AND // string to array $categories = array_filter(explode('+', $category)); // check if explode had results if (!empty($categories)) { foreach ($categories as $category) { $args['tax_query'][] = array('taxonomy' => 'dlm_download_category', 'field' => 'slug', 'terms' => $category, 'include_children' => $include_children); } } } else { // categories with OR // string to array $categories = array_filter(explode(',', $category)); // check if explode had results if (!empty($categories)) { $args['tax_query'][] = array('taxonomy' => 'dlm_download_category', 'field' => 'slug', 'terms' => $categories, 'include_children' => $include_children); } } } if (!empty($tags)) { $args['tax_query'][] = array('taxonomy' => 'dlm_download_tag', 'field' => 'slug', 'terms' => $tags); } } if ($featured === 'true' || $featured === true) { $args['meta_query'][] = array('key' => '_featured', 'value' => 'yes'); } if ($members_only === 'true' || $members_only === true) { $args['meta_query'][] = array('key' => '_members_only', 'value' => 'yes'); } ob_start(); // Allow filtering of arguments $args = apply_filters('dlm_shortcode_downloads_args', $args); $downloads = new WP_Query($args); $dlm_max_num_pages = $downloads->max_num_pages; // Template handler $template_handler = new DLM_Template_Handler(); if ($downloads->have_posts()) { ?> <?php echo html_entity_decode($loop_start); ?> <?php while ($downloads->have_posts()) { $downloads->the_post(); ?> <?php echo html_entity_decode($before); ?> <?php $template_handler->get_template_part('content-download', $template, '', array('dlm_download' => new DLM_Download(get_the_ID()))); ?> <?php echo html_entity_decode($after); ?> <?php } // end of the loop. ?> <?php echo html_entity_decode($loop_end); ?> <?php if ($paginate) { $template_handler->get_template_part('pagination', ''); } ?> <?php } wp_reset_postdata(); return ob_get_clean(); }