admin管理员组文章数量:1122846
I am using the loop in my custom page template as you can see in my code. Only 2 posts must be shown and for the rest I should be able to have pagination.
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts(
array (
'posts_per_page' => 2,
'post_type' => 'post',
'category_name' => 'news',
'category' => 1,
'paged' => $paged )
);
// The Loop
while ( have_posts() ) : the_post();?>
<div class="news-page-content-wrapper">
<div class="news-page-content">
<h1><a class="read-more"href="<?php the_permalink(); ?>"><?php the_title();?></a></h1>
<figure><?php the_post_thumbnail(); ?></figure>
<p><?php echo get_the_excerpt();?></p>
<a href="<?php the_permalink(); ?>">Read More»</a>
</div>
</div>
<?endwhile;
// Reset Query
wp_reset_query();
?>
<?php next_posts_link(); ?>
<?php previous_posts_link(); ?>
How can I have pagination using the loop with category ID?
I am using the loop in my custom page template as you can see in my code. Only 2 posts must be shown and for the rest I should be able to have pagination.
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts(
array (
'posts_per_page' => 2,
'post_type' => 'post',
'category_name' => 'news',
'category' => 1,
'paged' => $paged )
);
// The Loop
while ( have_posts() ) : the_post();?>
<div class="news-page-content-wrapper">
<div class="news-page-content">
<h1><a class="read-more"href="<?php the_permalink(); ?>"><?php the_title();?></a></h1>
<figure><?php the_post_thumbnail(); ?></figure>
<p><?php echo get_the_excerpt();?></p>
<a href="<?php the_permalink(); ?>">Read More»</a>
</div>
</div>
<?endwhile;
// Reset Query
wp_reset_query();
?>
<?php next_posts_link(); ?>
<?php previous_posts_link(); ?>
How can I have pagination using the loop with category ID?
Share Improve this question asked Feb 20, 2017 at 7:20 Sidney SousaSidney Sousa 2134 silver badges14 bronze badges2 Answers
Reset to default 0You can follow below URl to find your solution
How to fix pagination for custom loops?
You can use the tax_query filter: like this
$args = array
(
'post_type' => 'item',
'nopaging' => true,
'tax_query' => array
(
'taxonomy' => $taxonomy,
'field' => 'term_taxonomy_id',
'terms' => $term_id
),
'meta_query' => array(
'key' => 'from_import',
'value' => '1'
)
);
$posts = query_posts( $args );
本文标签: How to add pagination to custom page
版权声明:本文标题:How to add pagination to custom page 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736286883a1927762.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论