定制商店循环WooCommerce的分页

时间:2016-11-03 作者:rusya_sk

我正在使用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/这是函数中分页的me代码。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 个回复
最合适的回答,由SO网友:rusya_sk 整理而成

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