Category to display Page
-
Hi,
I am trying to build a custom page to show all products from two categories on the page linked (Mobiles and Tablets). However, I can’t list all the products. only a few. The pagination is not working too.
Here is my code.`<?php
// Template Name: Mobile Factory Outlet
//add_action( ‘woocommerce_before_shop_loop’, ‘woocommerce_pagination’, 10 );
$paged = ( get_query_var(‘paged’) ) ? get_query_var(‘paged’) : 1;
$count = isset( $_GET[‘count’] ) ? $_GET[‘count’] : 30;
//echo ‘<pre>’;print_r(get_query_var(‘paged’));echo ‘</pre>’;
//echo $count;
$args = array(
‘post_type’ => ‘product’,
‘paged’ => $paged,
‘posts_per_page’ => $count,
‘tax_query’ => array(
‘relation’ => ‘OR’,
array(
‘taxonomy’ => ‘product_cat’,
‘field’ => ‘slug’,
‘terms’ => ‘mobile’
),
array(
‘taxonomy’ => ‘product_cat’,
‘field’ => ‘slug’,
‘terms’ => ‘tablets’
)
),
);$wp_query = new WP_Query( $args );
get_header(‘shop’);
?>
<style>
body.archive.woocommerce #main{
padding-top:0;
}
</style>
<div style=”margin-bottom: 20px;”><?php layerslider(7) ?></div>
<?php
/**
* woocommerce_before_main_content hook
*
* @hooked woocommerce_output_content_wrapper – 10 (outputs opening divs for the content)
* @hooked woocommerce_breadcrumb – 20
*/
do_action(‘woocommerce_before_main_content’);
global $venedor_settings;
?>
<?php if ( $venedor_settings[‘category-title’] ) : ?>
<h1 class=”page-title”><?php woocommerce_page_title(); ?></h1>
<?php endif; ?><?php if ( $venedor_settings[‘category-description’] ) : ?>
<?php
/**
* woocommerce_archive_description hook
*
* @hooked woocommerce_taxonomy_archive_description – 10
* @hooked woocommerce_product_archive_description – 10
*/
do_action( ‘woocommerce_archive_description’ );
?>
<?php endif; ?><?php
if ( $wp_query->have_posts() ) :
?><div class=”content-before”>
<?php
/**
* woocommerce_before_shop_loop hook
*
* @hooked woocommerce_result_count – 20
* @hooked woocommerce_catalog_ordering – 30
*/
do_action( ‘woocommerce_before_shop_loop’ );
?>
</div><div class=”archive-products”>
<?php woocommerce_product_loop_start(); ?><?php woocommerce_product_subcategories(); ?>
<?php while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
<?php wc_get_template_part( ‘content’, ‘product’ ); ?>
<?php endwhile; // end of the loop. ?>
<?php woocommerce_product_loop_end(); ?>
</div><div class=”content-after”<?php if (!is_search() && !woocommerce_products_will_display()) echo ‘ style=”display:none;”‘ ?>>
<?php
/**
* woocommerce_after_shop_loop hook
*
* @hooked woocommerce_pagination – 10
*/
do_action( ‘woocommerce_after_shop_loop’ );
?>
</div><?php elseif ( ! woocommerce_product_subcategories( array( ‘before’ => woocommerce_product_loop_start( false ), ‘after’ => woocommerce_product_loop_end( false ) ) ) ) : ?>
<?php wc_get_template( ‘loop/no-products-found.php’ ); ?>
<?php endif; ?>
<?php
/**
* woocommerce_after_main_content hook
*
* @hooked woocommerce_output_content_wrapper_end – 10 (outputs closing divs for the content)
*/
do_action(‘woocommerce_after_main_content’);
?><?php
/**
* woocommerce_sidebar hook
*
* @hooked woocommerce_get_sidebar – 10
*/
do_action(‘woocommerce_sidebar’);
?><?php get_footer(‘shop’); ?>`
Ofcourse, I can list all the product at once by just making post_per_page variable => -1
However, this is not the ideal solution. It increaser the load time drastically and may even bring the site down. Can anyone please help as to what is wrong with the code.
Why isn’t the pagination not working.Thanks in advance ??
Regards,
DebashishThe page I need help with: [log in to see the link]
- The topic ‘Category to display Page’ is closed to new replies.