/** * Render main shortcode. * * @since 1.0.0 * @access public * @param array $atts * @param string $content * @return string */ public function render_shortcode($atts, $content = null) { $atts = shortcode_atts(array(), $atts, $this->shortcode); // must add the third params $this->shortcode, for builder shortcode rendering global $query_string, $TF; $output = ''; $build_query = array('post_type' => 'post'); if (TF_Model::is_template_page()) { query_posts(build_query($build_query)); } else { query_posts($query_string); } if (have_posts()) { $TF->in_archive_loop = true; the_post(); ob_start(); ?> <?php do_action('tf_single_loop_before_post'); ?> <article <?php echo tf_get_attr('post', $original_atts); ?> > <?php do_action('tf_single_loop_start_post'); ?> <?php echo do_shortcode($content); ?> <?php do_action('tf_single_loop_end_post'); ?> </article> <?php do_action('tf_single_loop_after_post'); ?> <?php $output .= ob_get_contents(); ob_get_clean(); $TF->in_archive_loop = false; } wp_reset_query(); return $output; }
/** * Render main shortcode. * * @since 1.0.0 * @access public * @param array $atts * @param string $content * @return string */ public function render_shortcode($original_atts, $content = null) { global $wp_query, $query_string, $TF; $atts = shortcode_atts(array('layout' => 'post-list', 'order' => 'DESC', 'orderby' => 'date', 'pagination' => 'yes'), $original_atts, $this->shortcode); $output = ''; $build_query = array('posts_per_page' => get_option('posts_per_page'), 'order' => $atts['order'], 'orderby' => $atts['orderby']); if (TF_Model::is_template_page()) { query_posts(build_query($build_query)); } else { //query_posts( array_merge( $wp_query->query_vars, $build_query ) ); // Fix Product archive page (site.com/shop) doesn't query product post_type, somehow using $query_string works. query_posts($query_string . '&' . build_query($build_query)); } if (have_posts()) { ob_start(); ?> <!-- loopswrapper --> <div class="tf_loops_wrapper clearfix <?php echo esc_attr($atts['layout']); ?> "> <?php $TF->in_archive_loop = true; while (have_posts()) { the_post(); ?> <?php do_action('tf_archive_loop_before_post'); ?> <article <?php echo tf_get_attr('post', $original_atts); ?> > <?php do_action('tf_archive_loop_start_post'); ?> <?php echo do_shortcode($content); ?> <?php do_action('tf_archive_loop_end_post'); ?> </article> <?php do_action('tf_archive_loop_after_post'); ?> <?php } $TF->in_archive_loop = false; ?> </div><!-- /tf_loops_wrapper --> <?php // Pagination links if ('yes' == $atts['pagination']) { get_template_part('includes/pagination', $wp_query->query_vars['post_type']); } $output = ob_get_contents(); ob_get_clean(); } wp_reset_query(); wp_reset_postdata(); return $output; }
/** * Render main shortcode. * * @since 1.0.0 * @access public * @param array $atts * @param string $content * @return string */ public function render_shortcode($original_atts, $content = null) { global $wp_query, $query_string, $TF; $atts = shortcode_atts(array('layout' => 'post-list', 'offset' => 0, 'post_per_page' => -1, 'order' => 'DESC', 'orderby' => 'date', 'pagination' => 'no', 'category' => array(0)), $original_atts, $this->shortcode); $output = ''; $paged = $this->get_paged_query(); $atts['category'] = html_entity_decode($atts['category'], ENT_COMPAT); $atts['category'] = maybe_unserialize($atts['category']); if (!$atts['category'] || empty($atts['category'])) { return false; } $build_query = array('order' => $atts['order'], 'orderby' => $atts['orderby']); $non_category = array_search(0, $atts['category']); $build_query['category__in'] = array(); if ($non_category !== false) { $categories = get_terms('category', array('hide_empty' => true)); foreach ($categories as $c) { $build_query['category__in'][] = $c->term_id; } } else { $build_query['category__in'] = $atts['category']; } $build_query['posts_per_page'] = $atts['post_per_page'] && $atts['post_per_page'] > 0 ? $atts['post_per_page'] : -1; $build_query['offset'] = ($paged - 1) * $atts['post_per_page'] + $atts['offset']; $build_query['nopaging'] = $build_query['posts_per_page'] == -1; $query = new WP_Query(build_query($build_query)); if ($query->have_posts()) { ob_start(); ?> <!-- loopswrapper --> <div class="tf_loops_wrapper clearfix <?php echo esc_attr($atts['layout']); ?> "> <?php $TF->in_archive_loop = true; while ($query->have_posts()) { $query->the_post(); ?> <?php do_action('tf_list_post_before_post'); ?> <article <?php echo tf_get_attr('post', $original_atts); ?> > <?php do_action('tf_list_post_start_post'); ?> <?php echo do_shortcode($content); ?> <?php do_action('tf_list_post_end_post'); ?> </article> <?php do_action('tf_list_post_after_post'); ?> <?php } $TF->in_archive_loop = false; ?> </div><!-- /tf_loops_wrapper --> <?php // Pagination links if ('yes' == $atts['pagination']) { echo tf_get_pagenav('', '', $query); } $output = ob_get_contents(); ob_get_clean(); } wp_reset_query(); wp_reset_postdata(); return $output; }