我无法在WordPress的Page.php中使分页工作。 这是代码:
global $query_string;
$ourCurrentPage = get_query_var('paged');
$post = array(
'post_per_page' => 10,
'paged' => $ourCurrentPage
);
$search_query = wp_parse_str( $query_string ,$post);
$search = new WP_Query( $search_query );
if ($search -> have_posts() ) {
while ($search -> have_posts() ) {
$search -> the_post();
...
...
//rest of loop
在法典中解释如何做,但无法使其工作
试试这段代码,
您可以在此处定义post_type属性中的自定义类型名称,然后您可以获得带有分页的列表帖子。
<?php
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$args = array(
'post_type' => 'page',
'orderby' => 'title',
'order' => 'ASC',
'posts_per_page' => 2,
'paged' => $paged
);
$the_query = new WP_Query($args);
?>
<?php if( $the_query->have_posts() ) : ?>
<!-- options -->
<div class="col-md-12 options border-bottom">
<!-- pagination -->
<ul class="pagination pull-right">
<li><?php echo get_next_posts_link( 'Next Page', $the_query->max_num_pages ); ?></li>
<li><?php echo get_previous_posts_link( 'Previous Page' ); ?></li>
</ul>
</div>
<!-- /.options -->
<!-- cemeteries -->
<div class="cemeteries">
<?php while( $the_query->have_posts() ) : $the_query->the_post(); ?>
<!-- pages -->
<div class="col-md-12">
<div class="col-md-4">
<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail('', array('class' => 'img-responsive'));
}
?>
</div>
<div class="col-md-8">
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
<p><a href="<?php the_permalink(); ?>"><button>Visit pages</button></a></p>
</div>
</div>
<!-- /.pages -->
<?php endwhile; ?>
</div>
<!-- /.cemetries -->
<!-- options -->
<div class="col-md-12 options border-bottom">
<!-- pagination -->
<ul class="pagination pull-right">
<li><?php echo get_next_posts_link( 'Next Page', $the_query->max_num_pages ); ?></li>
<li><?php echo get_previous_posts_link( 'Previous Page' ); ?></li>
</ul>
</div>
<!-- /.options -->
<?php wp_reset_postdata(); ?>
<?php else: ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
我希望这段代码对您有所帮助