我有一个问题,只在我的一个Wordpress页面上显示编号分页。
from flask.ext.mysql import MySQL
mysql = MySQL()
app = Flask(__name__)
# MySQL configurations
app.config['MYSQL_USER'] = 'root'
app.config['MYSQL_PASSWORD'] = 'root'
app.config['MYSQL_DB'] = 'DbToConnect'
app.config['MYSQL_HOST'] = 'localhost'
#Initialize the app for use with this MySQL class
mysql.init_app(app)
cursor = mysql.connection.cursor()
查询返回大约70个产品,所以我希望它至少显示7个数字。但是,它没有显示任何分页。
答案 0 :(得分:0)
如果您提供完整的代码,则可以更轻松地找到问题。
可能是你使用wp_reset_postdata();在the_posts_pagination();
之前请检查一下。
答案 1 :(得分:0)
尝试此代码,它肯定会帮助您
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
$args = array(
'post_type' => array (
'houten_vloeren', 'keramische_tegels', 'natuursteen_vloeren', 'tegels', 'laminaat', 'pvc_vloeren', 'tafels_stoelen',
),
'posts_per_page' => 5,
'post_status' => 'publish',
'paged' => $paged,
'meta_query' => array (
'key' => 'prijsknaller',
'value' => '1' ,
'compare' => '==',
//'type' => 'date',
),
);
$wp_query = new WP_Query( $args );
答案 2 :(得分:0)
用以下代码替换您的代码:
<?php
/**
* Template Name: Sale template
*/
?>
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
if ($paged == "1") {
$args = array(
'post_type' => array(
'houten_vloeren', 'keramische_tegels', 'natuursteen_vloeren', 'tegels', 'laminaat', 'pvc_vloeren', 'tafels_stoelen',
),
'posts_per_page' => 5,
'post_status' => 'publish',
'paged' => $paged,
'offset' => 0,
'meta_query' => array(
'key' => 'prijsknaller',
'value' => '1',
'compare' => '==',
//'type' => 'date',
),
);
} else {
$offset = $paged * 5;
$offset = $offset - 5;
$args = array(
'post_type' => array(
'houten_vloeren', 'keramische_tegels', 'natuursteen_vloeren', 'tegels', 'laminaat', 'pvc_vloeren', 'tafels_stoelen',
),
'posts_per_page' => 5,
'post_status' => 'publish',
'paged' => $paged,
'offset' => $offset,
'meta_query' => array(
'key' => 'prijsknaller',
'value' => '1',
'compare' => '==',
//'type' => 'date',
),
);
}
$query = new WP_Query($args);
?>
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="row">
<div class="product-overview">
<?php if ($query->have_posts()) :
while ($query->have_posts()) : $query->the_post(); ?>
<div class="col-md-3">
<div class="featured-block">
<div class="featured-block-image">
<a href="<?php the_permalink(); ?>"><img src="<?php the_field('productafbeelding'); ?>"
alt="<?php the_title(); ?>"></a>
</div>
<div class="featured-block-info">
<h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
<?php if (get_field('prijs_oud')) : ?>
<span class="oud"><?php the_field('prijs_oud'); ?></span>
<span class="nieuw"><?php the_field('prijs_nieuw'); ?></span> p/m<sub>2</sub>
</div>
</div>
</div>
<?php endwhile; ?>
<div class="pagination-grp">
<?php
$big = 999999999; // need an unlikely integer
//$i=1;
echo paginate_links(array(
'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
'format' => '?paged=%#%',
'current' => max(1, get_query_var('paged')),
'prev_text' => __('<'),
'next_text' => __('>'),
'total' => $loop->max_num_pages
));
wp_reset_postdata();
endif;
?>
</div>
</div>
</div>
</div>
</div>
</div>