我为我的博客页面制作了一个模板,可以在最近的博客中调用,每页显示2个博客。我在循环中添加了一个分页功能,但它只是一遍又一遍地调用相同的页面并显示相同的2个博客摘录,即使url读取/ blog / page / 2。但是,当我点击在类别档案中打开的博客中的分页链接时,分页工作并显示接下来的2个博客?请帮忙
博客页面模板:
<?php
/*
* Template Name: Blog Homepage
*/
get_header()?>
<main role="main">
<section>
<div id="bp-column-L">
<h1>Our Most Recent Blogs</h1>
<?php query_posts("posts_per_page=2"); ?>
<?php get_template_part('loop'); ?>
</div>
<?php get_sidebar(); ?>
</section>
</main>
</div>
<?php get_footer()?>
调用循环的php页面:
<?php if (have_posts()): while (have_posts()) : the_post(); ?>
<!--article-->
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<!-- post thumbnail -->
<?php if ( has_post_thumbnail()) : // Check if thumbnail exists ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
<?php the_post_thumbnail(array(120,120)); // Declare pixel size you need inside the array ?>
</a>
<?php endif; ?>
<!-- /post thumbnail -->
<!-- post title -->
<h2>
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
</h2>
<!-- /post title -->
<!-- post details -->
<span class="date"><?php the_time('F j, Y'); ?> <?php the_time('g:i a'); ?></span>
<span class="author"><?php _e( 'Published by', 'html5blank' ); ?> <?php the_author_posts_link(); ?></span>
<span class="comments"><?php if (comments_open( get_the_ID() ) ) comments_popup_link( __( 'Leave your thoughts', 'html5blank' ), __( '1 Comment', 'html5blank' ), __( '% Comments', 'html5blank' )); ?></span>
<!-- /post details -->
<?php html5wp_excerpt('html5wp_index'); // Build your custom callback length in functions.php ?>
<?php edit_post_link(); ?>
</article>
<!-- /article -->
<?php endwhile; ?>
<?php get_template_part('pagination'); ?>
<?php else: ?>
<!-- article -->
<article>
<h2><?php _e( 'Sorry, nothing to display.', 'html5blank' ); ?></h2>
</article>
<!-- /article -->
<?php endif; ?>
被调用的函数是:
function html5wp_pagination()
{
global $wp_query;
$big = 999999999;
echo paginate_links(array(
'base' => str_replace($big, '%#%', get_pagenum_link($big)),
'format' => '?paged=%#%',
'current' => max(1, get_query_var('paged')),
'total' => $wp_query->max_num_pages
));
}