我已经查找了分页脚本并将它们放在下面的代码中但没有任何作用,我如何在下面实现分页?
'<?php
$args = array( 'posts_per_page' => 10 );
$lastposts = get_posts( $args );
foreach ( $lastposts as $post ) :
setup_postdata( $post ); ?>
<div id="pbox">
<div id="pthumb"><a href="<?php the_permalink(); ?>" class="ptitle"><?php the_post_thumbnail('thumbnail', array('class' => 'mythumbnail')); ?></a></div>
<div id="pcontent">
<a href="<?php the_permalink(); ?>" class="ptitle"><?php the_title(); ?></a>
<?php the_excerpt(); ?><br />
Post Category: <b><?php the_category( ', ' ); ?></b>
</div>
</div>
<?php endforeach;
wp_reset_postdata(); ?>'
答案 0 :(得分:0)
试试这个:
您需要在参数内传递paged
参数,然后在函数max_num_pages
中传递paginate_links
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$args = array( 'posts_per_page' => 10 ,'paged'=>$paged);
$the_query = new WP_Query( $args );
while ($the_query ->have_posts()) : $the_query -> the_post();
?>
<div id="pbox">
<div id="pthumb"><a href="<?php the_permalink(); ?>" class="ptitle"><?php the_post_thumbnail('thumbnail', array('class' => 'mythumbnail')); ?></a></div>
<div id="pcontent">
<a href="<?php the_permalink(); ?>" class="ptitle"><?php the_title(); ?></a>
<?php the_excerpt(); ?><br />
Post Category: <b><?php the_category( ', ' ); ?></b>
</div>
</div>
<?php
endwhile;
$big = 999999999; // need an unlikely integer
echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $the_query->max_num_pages
) );
wp_reset_query();