正如您在我的代码中看到的那样,我正在自定义页面模板中使用循环。只有2个职位必须显示,其余我应该能够有分页。
<?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(); ?>
如何使用类别ID为的循环进行分页?
SO网友:lam
您可以使用tax\\u查询过滤器:如下所示
$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 );