我有一个名为Memberships
的简单页面模板。
我想要一个简单的WooCommerce产品列表,每页有50个项目。 在buttom上我需要一个分页元素,帮助我移动到接下来的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。
我尝试了许多东西来获得分页,没有任何效果。它只是没有向我展示分页元素或者没有让我转向下一个元素。
答案 0 :(得分:0)
<?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');