admin管理员组文章数量:1023764
I set post per page from setting>maximum post per page to 20. I have 2 different custom post types 'book' and 'author' for archives of each of them. I want to load different number of post in page. I want to load 20 book per page in book archive and 5 post in author archive in each page. I also use WP-PageNavi plugin.
Here is my code
<?php
$paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
$args = array( 'post_type' => 'Author','paged' => $paged,'posts_per_page' =>5 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); ?>
<a href="<?php the_permalink(); ?>" class="writer-link col-md-12 col-sm-12 col-xs-12">
<div class="writer-row1 col-md-12 col-sm-12 col-xs-12">
<div class="col-md-2 col-sm-3 col-xs-12 image-right">
<?php the_post_thumbnail('post-thumbnail',array('class' => 'img-responsive')); ?>
</div>
<div class="col-md-10 col-xs-12 col-sm-9 col-xs-12 pull-right writer-content">
<h3><?php the_title(); ?></h3>
<h4><?php the_field('auth-trans'); ?></h4>
<?php if ( get_field('writer-bio') ) {
echo '<p>'.get_field('writer-bio').'</p>';} ?>
<span>...</span>
</div>
</div>
</a>
<?php endwhile; // End of the loop. ?>
<div class="wp-pagenavi row">
<div id="wp_page_numbers text-center col-sm-6 center-margin">
<ul>
<li class="active_page text-center"><?php if(function_exists('wp_pagenavi')) { wp_pagenavi(array( 'query' => $loop )); } ?></li>
</ul>
</div>
</div>
No problem with book archive: it loads 20 posts. But I don't know how I can make author page to load just 5 post per page and after it has loaded 5 first posts it is going to next page.
I set post per page from setting>maximum post per page to 20. I have 2 different custom post types 'book' and 'author' for archives of each of them. I want to load different number of post in page. I want to load 20 book per page in book archive and 5 post in author archive in each page. I also use WP-PageNavi plugin.
Here is my code
<?php
$paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
$args = array( 'post_type' => 'Author','paged' => $paged,'posts_per_page' =>5 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); ?>
<a href="<?php the_permalink(); ?>" class="writer-link col-md-12 col-sm-12 col-xs-12">
<div class="writer-row1 col-md-12 col-sm-12 col-xs-12">
<div class="col-md-2 col-sm-3 col-xs-12 image-right">
<?php the_post_thumbnail('post-thumbnail',array('class' => 'img-responsive')); ?>
</div>
<div class="col-md-10 col-xs-12 col-sm-9 col-xs-12 pull-right writer-content">
<h3><?php the_title(); ?></h3>
<h4><?php the_field('auth-trans'); ?></h4>
<?php if ( get_field('writer-bio') ) {
echo '<p>'.get_field('writer-bio').'</p>';} ?>
<span>...</span>
</div>
</div>
</a>
<?php endwhile; // End of the loop. ?>
<div class="wp-pagenavi row">
<div id="wp_page_numbers text-center col-sm-6 center-margin">
<ul>
<li class="active_page text-center"><?php if(function_exists('wp_pagenavi')) { wp_pagenavi(array( 'query' => $loop )); } ?></li>
</ul>
</div>
</div>
No problem with book archive: it loads 20 posts. But I don't know how I can make author page to load just 5 post per page and after it has loaded 5 first posts it is going to next page.
Share Improve this question edited Sep 1, 2016 at 8:32 cjbj 15k16 gold badges42 silver badges89 bronze badges asked Sep 1, 2016 at 7:11 mkafiyanmkafiyan 1513 silver badges11 bronze badges2 Answers
Reset to default 4add below code in functions.php file , here "event" is custom post type (change it as per your post type) , so here it will display 6 post on events list page , also you need to copy default archive.php file and copy and create new archive-event.php (replace event with your post type).
function custom_type_archive_display($query) {
if (is_post_type_archive('event')) {
$query->set('posts_per_page',6);
$query->set('orderby', 'date' );
$query->set('order', 'DESC' );
return;
}
}
add_action('pre_get_posts', 'custom_type_archive_display');
Hope this Helps :)
More detail how to list custom post on custom page refer this link Custom Posts on Different Pages
You will have to make the query arguments dependend on the type of archive you are generating (which WP already knows from the page slug). Luckily there is a test for that, called is_post_type_archive
. In the beginning of your code you would include this:
if (is_post_type_archive('books')) {
$args = array( 'post_type' => 'Books','paged' => $paged,'posts_per_page' =>20 );
}
elseif (is_post_type_archive('author')) {
$args = array( 'post_type' => 'Author','paged' => $paged,'posts_per_page' =>5 );
}
I set post per page from setting>maximum post per page to 20. I have 2 different custom post types 'book' and 'author' for archives of each of them. I want to load different number of post in page. I want to load 20 book per page in book archive and 5 post in author archive in each page. I also use WP-PageNavi plugin.
Here is my code
<?php
$paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
$args = array( 'post_type' => 'Author','paged' => $paged,'posts_per_page' =>5 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); ?>
<a href="<?php the_permalink(); ?>" class="writer-link col-md-12 col-sm-12 col-xs-12">
<div class="writer-row1 col-md-12 col-sm-12 col-xs-12">
<div class="col-md-2 col-sm-3 col-xs-12 image-right">
<?php the_post_thumbnail('post-thumbnail',array('class' => 'img-responsive')); ?>
</div>
<div class="col-md-10 col-xs-12 col-sm-9 col-xs-12 pull-right writer-content">
<h3><?php the_title(); ?></h3>
<h4><?php the_field('auth-trans'); ?></h4>
<?php if ( get_field('writer-bio') ) {
echo '<p>'.get_field('writer-bio').'</p>';} ?>
<span>...</span>
</div>
</div>
</a>
<?php endwhile; // End of the loop. ?>
<div class="wp-pagenavi row">
<div id="wp_page_numbers text-center col-sm-6 center-margin">
<ul>
<li class="active_page text-center"><?php if(function_exists('wp_pagenavi')) { wp_pagenavi(array( 'query' => $loop )); } ?></li>
</ul>
</div>
</div>
No problem with book archive: it loads 20 posts. But I don't know how I can make author page to load just 5 post per page and after it has loaded 5 first posts it is going to next page.
I set post per page from setting>maximum post per page to 20. I have 2 different custom post types 'book' and 'author' for archives of each of them. I want to load different number of post in page. I want to load 20 book per page in book archive and 5 post in author archive in each page. I also use WP-PageNavi plugin.
Here is my code
<?php
$paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
$args = array( 'post_type' => 'Author','paged' => $paged,'posts_per_page' =>5 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); ?>
<a href="<?php the_permalink(); ?>" class="writer-link col-md-12 col-sm-12 col-xs-12">
<div class="writer-row1 col-md-12 col-sm-12 col-xs-12">
<div class="col-md-2 col-sm-3 col-xs-12 image-right">
<?php the_post_thumbnail('post-thumbnail',array('class' => 'img-responsive')); ?>
</div>
<div class="col-md-10 col-xs-12 col-sm-9 col-xs-12 pull-right writer-content">
<h3><?php the_title(); ?></h3>
<h4><?php the_field('auth-trans'); ?></h4>
<?php if ( get_field('writer-bio') ) {
echo '<p>'.get_field('writer-bio').'</p>';} ?>
<span>...</span>
</div>
</div>
</a>
<?php endwhile; // End of the loop. ?>
<div class="wp-pagenavi row">
<div id="wp_page_numbers text-center col-sm-6 center-margin">
<ul>
<li class="active_page text-center"><?php if(function_exists('wp_pagenavi')) { wp_pagenavi(array( 'query' => $loop )); } ?></li>
</ul>
</div>
</div>
No problem with book archive: it loads 20 posts. But I don't know how I can make author page to load just 5 post per page and after it has loaded 5 first posts it is going to next page.
Share Improve this question edited Sep 1, 2016 at 8:32 cjbj 15k16 gold badges42 silver badges89 bronze badges asked Sep 1, 2016 at 7:11 mkafiyanmkafiyan 1513 silver badges11 bronze badges2 Answers
Reset to default 4add below code in functions.php file , here "event" is custom post type (change it as per your post type) , so here it will display 6 post on events list page , also you need to copy default archive.php file and copy and create new archive-event.php (replace event with your post type).
function custom_type_archive_display($query) {
if (is_post_type_archive('event')) {
$query->set('posts_per_page',6);
$query->set('orderby', 'date' );
$query->set('order', 'DESC' );
return;
}
}
add_action('pre_get_posts', 'custom_type_archive_display');
Hope this Helps :)
More detail how to list custom post on custom page refer this link Custom Posts on Different Pages
You will have to make the query arguments dependend on the type of archive you are generating (which WP already knows from the page slug). Luckily there is a test for that, called is_post_type_archive
. In the beginning of your code you would include this:
if (is_post_type_archive('books')) {
$args = array( 'post_type' => 'Books','paged' => $paged,'posts_per_page' =>20 );
}
elseif (is_post_type_archive('author')) {
$args = array( 'post_type' => 'Author','paged' => $paged,'posts_per_page' =>5 );
}
本文标签: Different Limit number of post on different archive page
版权声明:本文标题:Different Limit number of post on different archive page 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745603309a2158584.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论