admin管理员组文章数量:1384341
I can't add a pagination to divide my posts between pages and navigate between pages. Currently all 20 posts I have loads at once. I want to add a pagination to the bottom of my Page and view posts by 5.
I have a custom post type that I defined as Project. I have 2 pages. Homepage and Journal. Homepage features the feed of my Project post type and Journal features my regular blog posts. I want both of these pages to have pagination.
My current index.php which is my Homepage is as follows:
<?php get_header(); ?>
<?php get_footer(); ?>
<div class="portfolioBlock">
<?php
$args = array('post_type' => 'project','posts_per_page' => 20 );
$loop = new WP_Query( $args );
if( $loop->have_posts() ):
while( $loop->have_posts() ): $loop->the_post();
get_template_part( 'content', get_post_format() );
endwhile;
endif;
?>
</div>
My readings settings is as follows:
I am curious if this is caused because of my custom post types, would appreciate any help or lead to help me add a pagination to the page.
When i tried the Googled solution paginate_links I didn't get any links. I also tried previous_posts_link() and that gives me the links and I can move between pages, but each page reloads the same 20 posts, without any diving it up.
Thanks a lot!
I can't add a pagination to divide my posts between pages and navigate between pages. Currently all 20 posts I have loads at once. I want to add a pagination to the bottom of my Page and view posts by 5.
I have a custom post type that I defined as Project. I have 2 pages. Homepage and Journal. Homepage features the feed of my Project post type and Journal features my regular blog posts. I want both of these pages to have pagination.
My current index.php which is my Homepage is as follows:
<?php get_header(); ?>
<?php get_footer(); ?>
<div class="portfolioBlock">
<?php
$args = array('post_type' => 'project','posts_per_page' => 20 );
$loop = new WP_Query( $args );
if( $loop->have_posts() ):
while( $loop->have_posts() ): $loop->the_post();
get_template_part( 'content', get_post_format() );
endwhile;
endif;
?>
</div>
My readings settings is as follows:
I am curious if this is caused because of my custom post types, would appreciate any help or lead to help me add a pagination to the page.
When i tried the Googled solution paginate_links I didn't get any links. I also tried previous_posts_link() and that gives me the links and I can move between pages, but each page reloads the same 20 posts, without any diving it up.
Thanks a lot!
Share Improve this question asked Apr 24, 2020 at 7:28 Izel MarasIzel Maras 1 1- For static page pagination is a little bit different because the global variable $post behave differently. You may refer this and this post to see if it helps. – 西門 正 Code Guy - JingCodeGuy Commented Apr 24, 2020 at 8:34
1 Answer
Reset to default 0If you want to show only 5 posts you should set posts_per_page
to 5.
And by setting paged
parameter to any number you want, you can query posts in a specific page.
For example if you want to get posts 6 to 10 you should do:
$args = array(
'post_type' => 'project',
'posts_per_page' => 5,
'paged' => 2
);
本文标签: previous post linkCan39t Add Pagination
版权声明:本文标题:previous post link - Can't Add Pagination 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744536579a2611352.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论