定制商店循环woocommerce的分页

时间:2016-11-03 07:29:30

标签: php wordpress pagination woocommerce

我在woocommerce存档产品页面上使用自定义商店循环。麻烦的是我还有一个额外的空页。这个分页适用于博客,但不是这里。

<?php
                $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
                $product = new WC_Product(get_the_ID());
                $params = array('posts_per_page' => 12, 'post_type' => 'product', 'paged' => $paged, 'tax_query' => array(
        array(
            'taxonomy' => 'product_cat',
            'field' => 'slug',
            'terms' => array( 'free' ),
            'operator' => 'NOT IN'
        )
    ));
                $wc_query = new WP_Query($params);
                ?>
                <?php if ($wc_query->have_posts()) : ?>
                <?php while ($wc_query->have_posts()) :
                $wc_query->the_post(); ?>
                <article class="portfolio__item portfolio__item--shop">
                    <figure class="blog__image-container">
                        <?php if ( has_post_thumbnail()) {the_post_thumbnail('thumb-blog' ,array("class"=>"portfolio__image post_thumbnail"));} ?>
                    </figure>
                    <h3 class="portfolio__content-title portfolio__content-title--shop"><?php the_title(); ?></h3>
                    <p class="portfolio__content-text portfolio__content-text--shop"><?php $product = new WC_Product(get_the_ID()); echo $product->get_price_html(); ?></p>
                        <div class="portfolio__content">
                            <img class="portfolio__content-image" src="<?php echo get_template_directory_uri(); ?>/img/link-loop.png" alt="" data-jslghtbx="<?php
                                $thumb_id = get_post_thumbnail_id();
                                $thumb_url = wp_get_attachment_image_src($thumb_id,'thumb-big', true);
                                echo $thumb_url[0];
                            ?>">
                            <a href="?add-to-cart=<?php echo $product->id; ?>" class="portfolio__link">
                                <p class="portfolio__content-text">Click to buy</p>
                            </a>
                        </div>

                </article>
                <?php endwhile; ?>

我如何解决这个问题? http://wrap-design.com/portfolio/ 这是我在function.php中的分页代码

function wp_corenavi() {
  global $wp_query;
  $pages = '';
  $max = $wp_query->max_num_pages;
  if (!$current = get_query_var('paged')) $current = 1;
  $a['base'] = str_replace(999999999, '%#%', get_pagenum_link(999999999));
  $a['total'] = $max;
  $a['current'] = $current;

  $total = 0; //1 - выводить текст "Страница N из N", 0 - не выводить
  $a['mid_size'] = 3; //сколько ссылок показывать слева и справа от текущей
  $a['end_size'] = 1; //сколько ссылок показывать в начале и в конце
  $a['prev_text'] = ''; //текст ссылки "Предыдущая страница"
  $a['next_text'] = ''; //текст ссылки "Следующая страница"

  if ($max > 1) echo '<div class="navigation">';
  if ($total == 1 && $max > 1) $pages = '<span class="pages">Страница ' . $current . ' из ' . $max . '</span>'."\r\n";
  echo $pages . paginate_links($a);
  if ($max > 1) echo '</div>';
}

1 个答案:

答案 0 :(得分:0)

这很奇怪,但是在wordpress设置中 - 在我的循环中阅读“博客页面最多显示”数字等于post_per_page一切正常!)