【问题标题】:WooCommerce Pagination with Custom Loop带有自定义循环的 WooCommerce 分页
【发布时间】:2015-08-09 09:01:27
【问题描述】:

我有一个名为 Memberships 的简单页面模板。

我想要一个简单的 WooCommerce 产品列表,每页包含 50 个项目。 在按钮上,我需要一个分页元素来帮助我移动到接下来的 50 个元素。

这是页面模板代码

<?php
/**
  * Template Name: Memberships
  */

if (!defined('ABSPATH')) exit; // Exit if accessed directly


/**
 *
 * <head>
 *
 */
get_template_part('partials/head', 'page');


/**
 *
 * Header
 *
 */
get_template_part('partials/header', 'page');


/**
 *
 * Content
 *
 */
?>

<div class="row">
        <div class="category-visual focuspoint" data-focus-x="0.59" data-focus-y="0.65" data-focus-w="720"
             data-focus-h="300">

            <?php echo get_the_post_thumbnail($page->ID, 'full'); ?>

            <div class="category-visual-text">
                <h1 class="headline"><?php echo the_title(); ?></h1>
                <span class="subheader"><?php echo get_post(759)->post_content; ?></span>
            </div>
        </div>

        <?php if(wc_memberships_is_user_active_member(get_current_user_id(), 'packagecloud-membership')) {?>
        <ul class="products">
            <?php
            $args = array(
                'post_type' => 'product',
                'posts_per_page' => 5,
                'tax_query' => array(
                    'relation' => 'OR',
                    array(
                        'taxonomy' => 'product_cat',
                        'field' => 'slug',
                        'terms' => 'packages'
                    ),
                    array(
                        'taxonomy' => 'product_cat',
                        'field' => 'slug',
                        'terms' => 'demo-packages'
                    )
                )
            );
            $loop = new WP_Query($args);
            if ($loop->have_posts()) {
                while ($loop->have_posts()) : $loop->the_post();
                    /*wc_get_template_part('content', 'product');*/
                    ?>
                    <ul>
                        <?php the_title(); ?>
                    </ul>

                    <?php
                endwhile;
            } else {
                echo __('No products found');
            }
            wp_reset_postdata();
            ?>
        </ul>
        <?php } else {
            echo get_current_user_id();
        } ?>

    </div>
</div>

<?php
/**
 *
 * Footer
 *
 */
get_template_part('partials/footer', 'page');


/**
 *
 * Foot
 *
 */
get_template_part('partials/foot', 'page'); ?>

这是output


我尝试了很多方法来获得分页,但没有任何效果。它只是不向我显示分页元素或不将我移动到下一个元素。

【问题讨论】:

    标签: php wordpress pagination woocommerce


    【解决方案1】:
    <?php
        /**
         * Template Name: Memberships
         */
    
        if (!defined('ABSPATH')) exit; // Exit if accessed directly
    
    
        /**
         *
         * <head>
         *
         */
        get_template_part('partials/head', 'page');
    
    
        /**
         *
         * Header
         *
         */
        get_template_part('partials/header', 'page');
    
    
        /**
         *
         * Content
         *
         */
        ?>
    
        <div class="row">
                <div class="category-visual focuspoint" data-focus-x="0.59" data-focus-y="0.65" data-focus-w="720"
                     data-focus-h="300">
                    <div class="category-visual-text">
                        <h1 class="headline packagecloud"><?php echo the_title(); ?></h1>
                        <span class="subheader packagecloud"><?php echo get_post(759)->post_content; ?></span>
                    </div>
                    <?php echo get_the_post_thumbnail($page->ID, 'full'); ?>
                </div>
    
                <?php if(wc_memberships_is_user_active_member(get_current_user_id(), 'packagecloud-membership')) {?>
                <div class="packagecloud-wrapper">
                    <ul class="products">
                        <?php
                        $args = array(
                            'post_type' => 'product',
                            'posts_per_page' => 50,
                            'paged' => get_query_var('paged'),
                            'orderby' => 'title',
                            'order' => 'ASC',
                            'tax_query' => array(
                                'relation' => 'OR',
                                array(
                                    'taxonomy' => 'product_cat',
                                    'field' => 'slug',
                                    'terms' => 'packages'
                                ),
                                array(
                                    'taxonomy' => 'product_cat',
                                    'field' => 'slug',
                                    'terms' => 'demo-packages'
                                )
                            )
                        );
                        $loop = new WP_Query($args);
                        do_action('woocommerce_before_shop_loop');
    
                        if ($loop->have_posts()) {
                            while ($loop->have_posts()) : $loop->the_post();
                                ?>
                                <ul>
                                    <?php the_title(); ?>
                                </ul>
    
                                <?php
                            endwhile;
    
                        } else {
                            echo __('No products found');
                        }
                        wp_reset_query();
                        wp_reset_postdata();
    
                        mx42_pagination($loop); ?>
    
    
                    </ul>
                </div>
    
                <?php } else {
                    echo the_excerpt();
                } ?>
    
            </div>
        </div>
    
        <?php
        /**
         *
         * Footer
         *
         */
        get_template_part('partials/footer', 'page');
    
    
        /**
         *
         * Foot
         *
         */
        get_template_part('partials/foot', 'page');
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-07
      • 2016-04-18
      • 2017-11-09
      • 2022-11-05
      • 2012-10-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多