블로그

Uncategorized

워드프레스의 우커머스 페이지네이션-페이징 붙이는 방법(woocommerce paging(

01_05
한국 쇼핑몰처럼 워드프레스의 우커머스에도 맨 아래쪽에 정상적인 페이징을 붙이려고 하면 

1. 해당페이지에 shortcode를 [product_category category=”xxx-카테로리” per_page=”12″ columns=”4″ orderby=”” order=”desc” paging=”yes”] 과 같이 삽입한다.
2. /wp-content/plugins/woocommerce/includes 의 폴더에서 – 이 상황은 우커머스의 버젼에 따라 달라 질 수 있다.
class-wc-shortcodes.php  에서 function product_category 부분을 찾아서 화일을 아래와 같이 수정한다. 여기서 빨간색
으로 된 부분만 추가한다.
public static function product_category( $atts ) {
global $woocommerce_loop;
if ( empty( $atts ) ) return ”;
extract( shortcode_atts( array(
‘per_page’ => ’12’,
‘columns’ => ‘4’,
‘orderby’ => ‘title’,
‘order’ => ‘desc’,
‘category’ => ”,
‘paging’ => ‘no’, // paging 건으로 추가함.
‘operator’ => ‘IN’ // Possible values are ‘IN’, ‘NOT IN’, ‘AND’.
), $atts ) );
if ( ! $category ) return ”;
// Default ordering args
$ordering_args = WC()->query->get_catalog_ordering_args( $orderby, $order );
$args = array(
‘post_type’ => ‘product’,
‘post_status’ => ‘publish’,
‘ignore_sticky_posts’ => 1,
‘orderby’ => $ordering_args[‘orderby’],
‘order’ => $ordering_args[‘order’],
‘posts_per_page’ => $per_page,
‘meta_query’ => array(
array(
‘key’ => ‘_visibility’,
‘value’ => array(‘catalog’, ‘visible’),
‘compare’ => ‘IN’
)
),
‘tax_query’ => array(
array(
‘taxonomy’ => ‘product_cat’,
‘terms’ => array( esc_attr( $category ) ),
‘field’ => ‘slug’,
‘operator’ => $operator
)
)
);
if ( $paging == ‘yes’ ) { // paging 건으로 추가 시작.
// paging
$paged = ( get_query_var( ‘paged’ ) ) ? get_query_var( ‘paged’ ) : 1;
$args[‘paged’] = $paged;
} // paging 건으로 추가 끝.
if ( isset( $ordering_args[‘meta_key’] ) ) {
$args[‘meta_key’] = $ordering_args[‘meta_key’];
}
ob_start();
$products = new WP_Query( apply_filters( ‘woocommerce_shortcode_products_query’, $args, $atts ) );
$woocommerce_loop[‘columns’] = $columns;
if ( $products->have_posts() ) : ?>
<?php woocommerce_product_loop_start(); ?>
<?php while ( $products->have_posts() ) : $products->the_post(); ?>
<?php wc_get_template_part( ‘content’, ‘product’ ); ?>
<?php endwhile; // end of the loop. ?>
<?php woocommerce_product_loop_end(); ?>
<?php endif;
if ( $paging == ‘yes’ ) { // paging 건으로 추가 시작.
// paging
$big = 999999999; // need an unlikely integer
$paginate = paginate_links( array(
‘base’ => str_replace( $big, ‘%#%’, esc_url( get_pagenum_link( $big ) ) ),
‘format’ => ‘?paged=%#%’,
‘current’ => max( 1, get_query_var(‘paged’) ),
‘type’ => ‘array’,
‘total’ => $products->max_num_pages
) );
if ( is_array($paginate) )
$paging_str = implode(‘ ‘, $paginate);
else
$paging_str = $paginate;
echo ‘<div class=”pagination”>’ . $paging_str . ‘</div>’;
} // paging 건으로 추가 끝.
woocommerce_reset_loop();
wp_reset_postdata();
return ‘<div class=”woocommerce columns-‘ . $columns . ‘”>’ . ob_get_clean() . ‘</div>’;
}

Leave a Reply

Your email address will not be published. Required fields are marked *