简体   繁体   中英

How to do the paging on my page of blogs?

I have a page which show the all the posts. I have used the following code.

$args = array( 'numberposts' => 0 );
$lastposts = get_posts( $args );
foreach($lastposts as $post) : setup_postdata($post); ?>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    <?php the_content(); ?>
<?php endforeach; ?>

The above code displays all the posts on my page.

But Now I want to to do the pagination on this page, to show 3 blog posts per page.

How will I do this. Please help.

I don't know why you are using this weird structure instead of the loop
Try making it into the loop in comibation with query_posts
After that try posts_nav_link , maybe this works now but I'm not sure

您可以使用Page Navi插件并将get_posts更改为query_posts,也可以使用此堆栈答案在Wordpress中对get_posts()进行分页。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM